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{};
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
IEmptyinterface and augment it later, but the compiler reduce theIEmptyinterface tonever, 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
IEmptyin nested generic function?🔎 Search Terms
closure, nested, generic, emtpy interface, never, narrow
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
.D.TSoutput:🙂 Expected behavior
.D.TSoutput: