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
Consider the following unions, where union B is designed to provide intellisense code completion (in contrast to A, which is narrowed down to only string by the TS compiler).
If DeepPartial is applied on unions like B we get an TS error when we try to assign an arbitrary string value.
typeA='foo'|'bar'|string;typeB='foo'|'bar'|(string&{});typeKey='x'|'y'|'z';typeADict=DeepPartial<Record<Key,A>>;typeBDict=DeepPartial<Record<Key,B>>;// - no code completion for values (as expected)// - no error (as expected)consta: ADict={x: 'foo',y: 'barrel'};// - code completion for values (as expected)// - TS error for any other string value than `foo` and `bar` (NOT expected)constb: BDict={x: 'foo',y: 'barrel'// TS error};
Description
Consider the following unions, where union
B
is designed to provide intellisense code completion (in contrast toA
, which is narrowed down to onlystring
by the TS compiler).If
DeepPartial
is applied on unions likeB
we get an TS error when we try to assign an arbitrary string value.Steps to Reproduce
Have a look at this Codesandbox:
https://codesandbox.io/s/issue-demo-utility-types-deeppartial-5zwnw?file=/src/index.ts
Expected behavior
DeepPartial
not breaking unions of string and string literals.Suggested solution(s)
DeepPartial
conditional expressions could check forPrimitive
.Project Dependencies
The text was updated successfully, but these errors were encountered: