type.isLiteral() returns false for boolean literals
See original GitHub issueTypeScript Version: 3.1.0-dev.20180728 (new in 3.0.1)
Search Terms: isLiteral()
Code
- Create a boolean literal in the compiler api.
- Call
isLiteral()
on it.
Change seems to be done here:
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:
- Created 5 years ago
- Reactions:2
- Comments:7 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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?I need it quite often and it’s annoying, see #22269