Skip to content

Type check fails when union type has more than 12 literalsΒ #61031

Closed
@hrjakobsen

Description

@hrjakobsen

πŸ”Ž 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

https://www.typescriptlang.org/play/?ts=5.8.0-dev.20250123#code/C4TwDgpgBAYglgGwRAJgSQMYHsB2UC8UA3gFBTlRzY4BcUAzsAE5w4DmZFArjgGaLIUAfjq8AhgnrQSAXxIlQkKAFU+A1JlwAVcNEKdyAHygByKrgD6ARhNQDUY2eoWATCfuPzOCwGZ3FB1MvCwAWfwpPZwBWcKMg5wA2WMCnSwB2ZMjLAA5M+MsATjzU7ysABmLgqxsPfNK3WpLrP3lFaFV+JA1qAmJ7LzoO9XRqHUh7Hk7BOmYuCFlW3ShNPEJ4LpHcQKGNlfleHgxgOC2MJggxYAgVgAoBlTVd0d0AGihJ4boAIywsZDEcABKKB0FZ9ALnYBcJh4UgBAJeF72AIfDb2ORyIA

πŸ’» 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions