Open
Description
π Search Terms
"generic type inferance"
π Version & Regression Information
- This is the behavior in version 5.5 & 5.7
β― Playground Link
π» Code
class DialogService {
open = <DialogData>(
component: ComponentType<TypedDialog<DialogData>>,
config: DialogData
) => {};
}
abstract class TypedDialog<DialogData> {
dialogData!: DialogData;
}
class Component extends TypedDialog<{
area: number;
// test: string; // uncomment to get error about area being nullable
}> {
area: number = this.dialogData.area;
}
const service = new DialogService();
const data = 2 as number | null;
service.open(Component, {
area: data, // currently no error, should be `Type 'number | null' is not assignable to type 'number'.`
});
declare interface ComponentType<T> {
new (...args: any[]): T;
}
π Actual behavior
when test
is not there, no error about type mismatch of area: data
π Expected behavior
type error at any time
Additional information about the issue
this seems like a bug as adding new properties show an already existing error.
but maybe I am just misunderstanding how typescript generics work?