Boolean["toString"] inconsistency
See original GitHub issueTypeScript Version: 3.4.0-dev.20190305
Code
const key: keyof Boolean = "toString"; // error - "toString" is not assignable to "valueOf"
const x: {toString(): string} = new Boolean(); // no error
const y: Boolean["toString"] = true.toString; // no error
class Bool extends Boolean {
protected toString() { // also no error, but should be
return "";
}
}
Expected behavior:
keyof Boolean
should be "toString" | "valueOf"
Playground
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Groovy Truth: string to boolean inconsistency? - Stack Overflow
Allocates a Boolean object representing the value true if the string argument is not null and is equal, ignoring case, to the string...
Read more >Try explain the JavaScript's truth inconsistency
This function works as a simple switch statement – It returns a boolean value based on matching argument. Above image presents the ToBoolean ......
Read more >typeof - JavaScript - MDN Web Docs - Mozilla
The typeof operator returns a string indicating the type of the operand's value.
Read more >Make string to boolean and boolean to string type casting in ...
A False boolean is type casted to a 'false' string. But a 'false' string is type casted to a True boolean. ... This...
Read more >LSInconsistency (LocalSolver 11.5 API)
Also known as Irreductible Inconsistent Subproblem. ... boolean, equals(java.lang.Object obj) ... Overrides: toString in class java.lang.
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
No, I right.
Unlike
Boolean
,Number
,String
, andSymbol
have explicitly-declaredtoString
methods in their corresponding interface, which is whytoString
is in theirkeyof
s, which is why I proposed addingtoString
toBoolean
’s interface.Abbreviated summary: we’re using the TypeScript type system to transform calls of the form x.toString() into AppropriateClass.prototype.toString.call(x). Without accurate information about the methods in x’s prototype chain, this is not possible.
In general, anything which is relying on the TypeScript definitions giving an accurate summary of what methods a class has will encounter this problem.