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
The type created by Object.Partial is weaker than expected
Reproduce the bug
typeT={x: {y: never;z: ()=>1}}// No errorconsterr: Object.Partial<T,'deep'>={x: {z: ()=>'test'}}
Expected behavior
tsc should produce an error:
(property) z?: (() => 1) | undefined
Type '() => string' is not assignable to type '() => 1'.
Type 'string' is not assignable to type '1'.ts(2322)
Possible Solution
typeDeepPartial<T>=TextendsRecord<string,unknown>
? Partial<{[KeyinkeyofT]: DeepPartial<T[Key]>}>
: T// Error: ... Type 'string' is not assignable to type '1'.ts(2322)constok: DeepPartial<T>={x: {z: ()=>'test'}}
The text was updated successfully, but these errors were encountered:
Type 'A' is not assignable to type 'OptionalDeep<A>'.
Types of property 'foo' are incompatible.
Type 'unknown' is not assignable to type 'OptionalDeep<unknown> | undefined'.
Type 'unknown' is not assignable to type 'OptionalDeep<unknown>'.(2322)
Normally unknown can never be passed into OptionalDeep because of the constraint T extends object. However when unknown is a value type of an object, it bypassed the constraint, resulting incorrect type OptionalDeep<unknown>.
IMO unknown may need to have special treatment to avoid this pitfall.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
馃悶 Bug Report
Describe the bug
The type created by Object.Partial is weaker than expected
Reproduce the bug
Expected behavior
tsc should produce an error:
Possible Solution
The text was updated successfully, but these errors were encountered: