Closed
Description
π Search Terms
"12 limit union type", "union type subtyping literals"
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about union types
β― Playground Link
π» Code
type FilledIcon = {
icon: string
unfilled?: false
}
type UnfilledIconType =
| 'icon_1'
| 'icon_2'
| 'icon_3'
| 'icon_4'
| 'icon_5'
| 'icon_6'
| 'icon_7'
| 'icon_8'
| 'icon_9'
| 'icon_10'
| 'icon_11'
| 'icon_12'
| 'icon_13'
type UnfilledIcon = {
icon: UnfilledIconType
unfilled: true
}
type Icon = FilledIcon | UnfilledIcon
function createIcon(icon: UnfilledIconType, unfilled: boolean) : Icon {
return {
icon,
unfilled
}
}
π Actual behavior
Typescript reports the following error:
Type '{ icon: UnfilledIconType; unfilled: boolean; }' is not assignable to type 'Icon'.
Type '{ icon: UnfilledIconType; unfilled: boolean; }' is not assignable to type 'UnfilledIcon'.
Types of property 'unfilled' are incompatible.
Type 'boolean' is not assignable to type 'true'.(2322)
π Expected behavior
Should type check without problems.
{ icon: 'icon_1' unfilled: true }
would be a valid UnfilledIcon
, and { icon: 'icon_1' unfilled: false }
would be a valid FilledIcon
.
Additional information about the issue
This only seems to happen if UnfilledIconType
has more than 12 literals. Removing icon_13
causes the type check to succeed.
Metadata
Metadata
Assignees
Labels
No labels