I'm currently developing a project that follows this particular structure:
interface IAuthProvider {
middleware: () => void
getInput: () => void
}
class Password implements IAuthProvider {
middleware = () => {}
getInput = () => {}
}
class Email implements IAuthProvider {
middleware = () => {}
getInput = () => {}
}
const providerNames = ['Email', 'Password']
type AuthProviderNamespace = { [K in typeof providerNames[number]]: IAuthProvider }
// error: Type 'typeof Password' is missing the following properties from type 'IAuthProvider': middleware, getInput
const providers: AuthProviderNamespace = { Email, Password }
I have to utilize AuthProviderNamespace
because such an object will be imported into a module and directly passed to a function for iteration purposes:
import * as AuthProviders from './providers/index.ts'
const providers = instantiateProviders(AuthProviders)
Therefore, I need to define the type of AuthProviders
. However, my implementation seems flawed as TypeScript fails to recognize Email and Password as valid implementations of IAuthProvider. Is there a way to resolve this issue?
Playground: https://tsplay.dev/wQV7jN