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
typeUndefinedKeys<T>={[PinkeyofT]: undefinedextendsT[P] ? P : never}[keyofT]typeOptionalUndefined<T>=Partial<Pick<T,UndefinedKeys<T>>>&Omit<T,UndefinedKeys<T>>typeTSample<UextendsRecord<string,any>|undefined,DextendsRecord<string,any>>={undef: U,def: D}functionfn<UextendsRecord<string,any>|undefined,DextendsRecord<string,any>>(params: OptionalUndefined<TSample<U,D>>){{// ERROR: both properties do not exist on type 'OptionalUndefined<TSample<U, D>>'const{ def, undef }=params}{// works as expectedconst{ def, undef }=paramsasOptionalUndefined<TSample<Record<string,any>|undefined,Record<string,any>>>}}
🙁 Actual behavior
typescript cannot properly determine parameter type
🙂 Expected behavior
I expect typescript to use definition of U (extends Record<string, any> | undefined) and D (``) to be used to determine the type of parameters and params should have `{ undef?: Record<string, any> | undefined, def: Record<string, any> }` type?
Notice how, when I explicitly specify the type of params, it works properly.
The text was updated successfully, but these errors were encountered:
Bug Report
I've created a type that converts all undefined properties to optional. This types works well, however fails when used in generic functions:
🔎 Search Terms
generic function
🕗 Version & Regression Information
This is the behavior in every version I tried ( 5.0.2 and 4.9.5 )
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
typescript cannot properly determine parameter type
🙂 Expected behavior
I expect typescript to use definition of U (
extends Record<string, any> | undefined
) and D (``) to be used to determine the type of parameters andparams
should have `{ undef?: Record<string, any> | undefined, def: Record<string, any> }` type?Notice how, when I explicitly specify the type of params, it works properly.
The text was updated successfully, but these errors were encountered: