TypeScript Version: 4.0.2
Search Terms:
new constructor params generic
Code
interface IDialog {
title: string;
}
class MyComponent {
constructor() {
}
}
interface IComponentFactory<T> {
new(dialog: IDialog): T
}
const a: IComponentFactory<MyComponent> = MyComponent; // expect it to fail cause MyComponent constructor does not have dialog: IDialog argument
Expected behavior:
expect compiler to fail cause MyComponent constructor does not have dialog: IDialog argument
Actual behavior:
compiler do not fail
Playground Link: https://www.typescriptlang.org/play?noUnusedLocals=true&noUnusedParameters=true#code/JYOwLgpgTgZghgYwgAgJIBFhwDYHsDmyA3gFDLnJjBjYQBcyAzmFKPgNwkC+JJC2cRo2QBZAJ4BhXAFsADrhARwxMhQQLmUAK4IwuKAAoAlCorIePPgKGjJM+YvAAmU2o0sdewwBMsefAwYfgQmpGZm6iCMuLQAdP4GvjghnGYWvPyCwuJScgpKYADMruSRmp76icEByCBa0gBG0KGq4chlMRDxBFXJ+EapFOkkoJCwiCiouQ4FAGKIXmJOADwAKgB8JbUQAO69-oGYfUYMq9wZ1sIACriyWrIAytAAbsBIW3cN2G-It0prUiiHl0+mQEAAHpAQN5hFN7PlwPMQVAlstUEC4CAkKsxLIIAD3NpkesSQZ1HlHGBToDysiWm1yFAIGAtFAQNsdu14ZSDGEGWYqDR6MgAOSQZgi1rhLgDKXDMpgJgvN4oAC8HOQNzuj2VSGMnBIjF1XT+IAMOW5BQGyAA9Da0MgAKLgvG6ZDUSi4ZDwYDYdpwLRG5DPXDAbzIZaqzZBPqG42xU3muwUgpOWVGqCvJAJvFmi0p8CFWVAA
Related Issues:
https://github.com/microsoft/TypeScript/wiki/FAQ#why-are-functions-with-fewer-parameters-assignable-to-functions-that-take-more-parameters
Thanks @MartinJohns
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
Most helpful comment
https://github.com/microsoft/TypeScript/wiki/FAQ#why-are-functions-with-fewer-parameters-assignable-to-functions-that-take-more-parameters