Typescript: Interface-constructor parameters not checked

Created on 2 Oct 2020  路  3Comments  路  Source: microsoft/TypeScript


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:

Working as Intended

Most helpful comment

https://github.com/microsoft/TypeScript/wiki/FAQ#why-are-functions-with-fewer-parameters-assignable-to-functions-that-take-more-parameters

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MartynasZilinskas picture MartynasZilinskas  路  3Comments

kyasbal-1994 picture kyasbal-1994  路  3Comments

manekinekko picture manekinekko  路  3Comments

Roam-Cooper picture Roam-Cooper  路  3Comments

siddjain picture siddjain  路  3Comments