Skip to content

Emtpy interface reduced to never in nested generic function  #49536

Description

@panmenghan

Bug Report

I can't find the docs about this behavior or google. I am not sure this is a bug.

My intention was define the IEmpty interface and augment it later, but the compiler reduce the IEmpty interface to never, my current workaround that have to define two dummy properties or not use nested function(or closure).

Is there a right way to force the compiler to keep the IEmpty in nested generic function?

🔎 Search Terms

closure, nested, generic, emtpy interface, never, narrow

🕗 Version & Regression Information

  • This is the behavior from v4.2.3 to v4.7.3

⏯ Playground Link

Playground link with relevant code

💻 Code

// empty interfaceinterfaceIEmpty{}exportfunctionfunc<TextendskeyofIEmpty>(){}exportfunctionmakeFunc(){functionnestedFunc<TextendskeyofIEmpty>(){}returnnestedFunc}// interface with one propertyinterfaceIOneProperty{a: string}exportfunctionfuncOneProperty<TextendskeyofIOneProperty>(){}exportfunctionmakeFuncOneProperty(){functionnestedFunc<TextendskeyofIOneProperty>(){}returnnestedFunc}// interface with two propertiesinterfaceITwoProperty{a: stringb: string}exportfunctionfuncTwoProperty<TextendskeyofITwoProperty>(){}exportfunctionmakeFuncTwoProperty(){functionnestedFunc<TextendskeyofITwoProperty>(){}returnnestedFunc}

🙁 Actual behavior

.D.TS output:

interfaceIEmpty{}exportdeclarefunctionfunc<TextendskeyofIEmpty>(): void;exportdeclarefunctionmakeFunc(): <Textendsnever>()=>void;// <-- unexpected: `keyof IEmpty` replaced by `never`interfaceIOneProperty{a: string;}exportdeclarefunctionfuncOneProperty<TextendskeyofIOneProperty>(): void;exportdeclarefunctionmakeFuncOneProperty(): <Textends"a">()=>void;// <-- same hereinterfaceITwoProperty{a: string;b: string;}exportdeclarefunctionfuncTwoProperty<TextendskeyofITwoProperty>(): void;exportdeclarefunctionmakeFuncTwoProperty(): <TextendskeyofITwoProperty>()=>void;export{};

🙂 Expected behavior

.D.TS output:

interfaceIEmpty{}exportdeclarefunctionfunc<TextendskeyofIEmpty>(): void;exportdeclarefunctionmakeFunc(): <TextendsIEmpty>()=>void;interfaceIOneProperty{a: string;}exportdeclarefunctionfuncOneProperty<TextendskeyofIOneProperty>(): void;exportdeclarefunctionmakeFuncOneProperty(): <TextendsIOneProperty>()=>void;interfaceITwoProperty{a: string;b: string;}exportdeclarefunctionfuncTwoProperty<TextendskeyofITwoProperty>(): void;exportdeclarefunctionmakeFuncTwoProperty(): <TextendskeyofITwoProperty>()=>void;export{};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Needs InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions