I have an abstract class with a Generic that I implement with a Union type such as :
export abstract class DAO<T> {
async getDocument(ref: string): Promise<T> {
// irrelevant code that return T asynchronously
}
}
export class ConfigurationDAO extends DAO<ConfigurationType> {
//...
}
export type ConfigurationType = 'advertising' | 'theming';
The getDocument()
signature for the ConfigurationDAO
class is then :
async getDocument(ref: string): Promise<ConfigurationType>
The problem is that when I call this function, I have an error :
const advertisingDocument: 'advertising' = await this.getDocument('advertising');
the error :
Type 'ConfigurationType' is not assignable to type '"advertising"'.
Type '"theming"' is not assignable to type '"advertising"'
I don't understand why the 'advertising'
type is not valid when the return type is 'advertising' | 'theming'