You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When omitting [props whose values are functions] from a type, if the function includes a keyof X parameter, the TS type is correctly narrowed, but the runtime type still includes that prop.
import{typeOf,ReflectionKind}from'@deepkit/type';exportclassSomeClass{fieldA!: string;fieldB!: number;fieldC!: boolean;someFunctionA(){}someFunctionB(input: string){}someFunctionC(input: keyof this /* behaves the same with keyof anything */){}}exporttypeArrowFunction=(...args: any)=>any;typeMethodKeys<T>={[KinkeyofT]: T[K]extendsArrowFunction ? K : never}[keyofT];exporttypeEntityFields<Textendsobject>=Omit<T,MethodKeys<T>>;functiontypeTest(): EntityFields<SomeClass>{returnnullasany;}consttheType=typeOf<typeoftypeTest>();console.log(theType.kind===ReflectionKind.function&&theType.return);// output yields subtypes fieldA, fieldB, fieldC, and someFunctionC// the TS type does NOT include someFunctionC
Unfortunately, reference to this is not implemented at all in our type compiler, so referring to it breaks stuff in unexpected ways. I've added now a workaround that keyof this is handled as any (instead of never), so that your code should work. Please test and let me know! Thanks
When omitting [props whose values are functions] from a type, if the function includes a
keyof X
parameter, the TS type is correctly narrowed, but the runtime type still includes that prop.Sandbox: https://replit.com/@fergusean/DKTypeIssueDemo2
Code:
Output:
The text was updated successfully, but these errors were encountered: