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
This is working as intended. Exclude<> is used to remove types from a union type. string is not a union type, so the literal type 'Z' can be removed from it. For this to work TypeScript would need to support types like "a string, but not...", which it does not. The relevant issues for this are #4196 / #29317.
Reacted by Andrii Dieiev, Ufuk Bakan and Bruce Pascoe
However i still couldnt map my type, Omit is not working too :
typecomments={[key: string]: string}typehasSum={sum: number}typemergedType=Omit<comments,"sum">&hasSum;constmerged: mergedType={sum: 1// type error can not assign number to string}
I was aware its working with union types and thought when there is unlimited types , its bottlenecked.
No, the depth limit is about types that are defined recursively, it has nothing to do with the number of values inhabiting the type or even whether the type is finite. The reason this doesn't work is simply because primitives like string are not union types and TS has no way internally to represent types like string & NOT "foo", so Exclude/Omit can't do anything with them.
This is effectively a duplicate of #4196 because you're what you're trying to do requires support for negated types.
Activity
MartinJohns commentedon Mar 30, 2023
You forgot to fill out the issue template.
This is working as intended.
Exclude<>is used to remove types from a union type.stringis not a union type, so the literal type'Z'can be removed from it. For this to work TypeScript would need to support types like "a string, but not...", which it does not. The relevant issues for this are #4196 / #29317.fatcerberus commentedon Mar 30, 2023
Also I’m not really sure what this has to do with a depth limit?
typescript-bot commentedon Apr 1, 2023
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
ufukbakan commentedon Apr 4, 2023
I was aware its working with union types and thought when there is unlimited types , its bottlenecked.
ufukbakan commentedon Apr 4, 2023
However i still couldnt map my type, Omit is not working too :
fatcerberus commentedon Apr 4, 2023
No, the depth limit is about types that are defined recursively, it has nothing to do with the number of values inhabiting the type or even whether the type is finite. The reason this doesn't work is simply because primitives like
stringare not union types and TS has no way internally to represent types likestring & NOT "foo", soExclude/Omitcan't do anything with them.This is effectively a duplicate of #4196 because you're what you're trying to do requires support for negated types.