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.

Boolean["toString"] inconsistency

See original GitHub issue

TypeScript 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:open
  • Created 5 years ago
  • Reactions:1
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

7reactions
RyanCavanaughcommented, Mar 5, 2019

you wrong. keyof of any other type

No, I right.

interface Foo { m; }
// Error
const k: keyof Foo = "toString";

Unlike Boolean, Number, String, and Symbol have explicitly-declared toString methods in their corresponding interface, which is why toString is in their keyofs, which is why I proposed adding toString to Boolean’s interface.

4reactions
domeniccommented, Sep 13, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

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