-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
type.isLiteral() returns false for boolean literals #26075
Comments
This is because a boolean literal type is actually not represented by a |
Let's chat whether we should fix this @weswigham. |
@ajafff oh yeah, good point! These methods on Another point: the common interface LiteralType extends Type {
value: string | number;
// ...
} So That said, as an API user it does seem a bit unexpected that boolean literal types aren't included with |
I need it quite often and it's annoying, see #22269 |
Consensus was that this function should return |
is that mean we want boolean to be a literal?(booleanLiteral extends Literal and has a boolean 'value' prop) |
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 |
Due to microsoft/TypeScript#26075 true and false are not considered literal. This CL change the condition when checking for the expression on the if statement to correctly handle literable booleans
TypeScript Version: 3.1.0-dev.20180728 (new in 3.0.1)
Search Terms: isLiteral()
Code
isLiteral()
on it.Change seems to be done here:
e46d214#diff-233e1126c0abc811c4098757f9e4516eR428
Expected behavior:
true
for a boolean literal type (true
orfalse
)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 returntrue
for boolean literals inisLiteralType
.The text was updated successfully, but these errors were encountered: