microsoft / microsoft/TypeScript

Compiler Errors TS1110 and TS2345 with integer type pattern

Open
#27,178 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: Literal Types In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.0.3

Explicitly marked positive integers are not recognized in a type pattern:

    foo(direction: -1 | 1 | -2 | +2) { }

image

Likewise, calling it using a perfectly legit integer fails with TS2345:

image

Expected behavior:

As everywhere else, the unary operator + should be allowed in a type pattern.
This is not urgent, just for completeness.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Reproduce the example with TypeScript 3.0.3, checking both the type pattern -1 | 1 | -2 | +2 and calls using integer values; done means unary + is accepted in the type pattern and the corresponding TS1110 and TS2345 errors no longer occur.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.