Skip to content

Crash when generating a type (via template literals) that is too largeΒ #46480

@LukeChannings

Description

@LukeChannings

Bug Report

πŸ•— Version & Regression Information

  • This is a crash

I have tested this with 4.4.3, 4.4.4, and 4.5.0-dev.20211022 (linked playground)

⏯ Playground Link

Playground

πŸ’» Code

export type Spacing =
    | `0`
    | `${number}px`
    | `${number}rem`
    | `s${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20}`;

const spacing: Spacing = "s12"

export type SpacingShorthand =
    | `${Spacing} ${Spacing}`
    | `${Spacing} ${Spacing} ${Spacing}`
    | `${Spacing} ${Spacing} ${Spacing} ${Spacing}`;

const test: SpacingShorthand = "0 0 0";

I can get a working version by replacing:

-     | `s${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20}`;
+     | `s${number}`

πŸ™ Actual behavior

tsc crashes with the following error:

node_modules/typescript/lib/tsc.js:92656
    throw e;
    ^

RangeError: Value undefined out of range for undefined options property undefined
    at Map.set (<anonymous>)
    at recursiveTypeRelatedTo (node_modules/typescript/lib/tsc.js:51947:30)
    at isRelatedTo (node_modules/typescript/lib/tsc.js:51527:34)
    at checkTypeRelatedTo (node_modules/typescript/lib/tsc.js:51213:26)
    at isTypeRelatedTo (node_modules/typescript/lib/tsc.js:51176:24)
    at isTypeSubtypeOf (node_modules/typescript/lib/tsc.js:50459:20)
    at node_modules/typescript/lib/tsc.js:48286:90
    at Object.some (node_modules/typescript/lib/tsc.js:662:25)
    at _loop_16 (node_modules/typescript/lib/tsc.js:48286:45)
    at removeStringLiteralsMatchedByTemplateLiterals (node_modules/typescript/lib/tsc.js:48291:21)

πŸ™‚ Expected behavior

The SpacingShorthand type should be computed.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptCrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad output

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions