Skip to content

Generic type inferance not workingΒ #60981

Open
@aceArt-GmbH

Description

πŸ”Ž Search Terms

"generic type inferance"

πŸ•— Version & Regression Information

  • This is the behavior in version 5.5 & 5.7

⏯ Playground Link

https://www.typescriptlang.org/play/?jsx=0#code/MYGwhgzhAEAiCWYQHsDmBlApgJwG72E2gG8AoaC6ZAB0wDtoBeaAHgSTVjABcwA+ABTlKI4MgC21ZHXrcAXNADCEqTLrcAKgE9aLbbQAm7FKjaITXXnz4AaYSIpi6AM3ioFxzjzD3oASiY+EgBfAG5SYNJSMAAjCG5sMGBuaFBIGH1MI3M0Mw5US34SXwMcgu8AQg8ywvDI0jSoJRVpWWhMAA9uegMMnSzPUzIRMGxMMAU6AFdxGJxwygB6Rehu+IV47Hg6VFDoZegpujFxcTbuZGhUTBScbGRsaFjkKZTR8eg57dRoaZBwGIgTARILDSjvCa-GZzR7MbgAC3gEAAdKV8oVkRC6lEnPFoBAcPhCExfpgAO5wMpYPAETACPzhBrSPEGbwkgBMTxg01mOGgAB8of9GQSaYRkTR6AJlJJWuobMURmNIazeAqDsAptgxuoQFpfpc7g8FRB4S8QAZPkQAAaZaAAch5MIFQpA9ugSINbygbjosSBq0u3H6DqdOHtyOtEQZUQMmDSYw96hwziSRBlqlkmT0oN8MgpAmRRdGqAgCjAdC0AG0ALp+BQaOpAA

πŸ’» 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?

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions