Microsoft/TypeScript

type.isLiteral() returns false for boolean literals

Open

#26.075 aperta il 31 lug 2018

Vedi su GitHub
 (7 commenti) (2 reazioni) (0 assegnatari)TypeScript (6726 fork)batch import
BugDomain: APIDomain: Literal TypesHelp Wanted

Metriche repository

Star
 (48.455 star)
Metriche merge PR
 (Merge medio 6g 17h) (9 PR mergiate in 30 g)

Descrizione

TypeScript Version: 3.1.0-dev.20180728 (new in 3.0.1)

Search Terms: isLiteral()

Code

  1. Create a boolean literal in the compiler api.
  2. Call isLiteral() on it.

Change seems to be done here:

https://github.com/Microsoft/TypeScript/commit/e46d214fceb72cc76145779543bf871ce9ff66b0#diff-233e1126c0abc811c4098757f9e4516eR428

Expected behavior: true for a boolean literal type (true or false)

Actual behavior: false

I have a few tests for assumptions about the compiler api in ts-simple-ast and this one started failing. Maybe it's not a bug, but I thought I would log it anyway to find out why this behaviour changed.

Is it because it doesn't have the Unit flag while string and number literals do? For what it's worth, in checker.ts it will internally return true for boolean literals in isLiteralType.

Guida contributor