question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

type.isLiteral() returns false for boolean literals

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
marijnhcommented, Jul 8, 2019

I just ran into this too (needing to use undocumented internals to get at the value of a boolean literal type). So to second @Kingwl 's question—is the intent to add a BooleanLiteralType interface to the public API? Anything someone undertaking such a change should be careful about?

1reaction
ajafffcommented, Jul 31, 2018

That said, as an API user it does seem a bit unexpected that boolean literal types aren’t included with LiteralType, but I don’t have a use case where it would matter.

I need it quite often and it’s annoying, see #22269

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handbook - Literal Types - TypeScript
There are three sets of literal types available in TypeScript today: strings, numbers, and booleans; by using literal types you can allow an...
Read more >
javascript - What's the difference between a boolean literal ...
Answering the main question, booleans can only have two literals: false and true , and every boolean variable is a boolean value. You...
Read more >
Literal types and Enums - mypy 0.991 documentation
Literal types let you indicate that an expression is equal to some specific primitive value. For example, if we annotate a variable with...
Read more >
Literals in Python - GeeksforGeeks
Python has different types of literal such as: String literals; Numeric literals; Boolean literals; Literal Collections; Special literals ...
Read more >
RDFNode (OWLAPI :: Distribution 4.5.19 API)
Modifier and Type, Method and Description ... abstract boolean, isAnonymous() ... Returns: true if this is a resource node (i.e. isLiteral returns false...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found