-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Boolean["toString"] inconsistency #30225
Comments
Apparent properties (such as I think we could safely add |
@RyanCavanaugh you wrong. keyof of any other type includes toString. For example: |
No, I right. interface Foo { m; }
// Error
const k: keyof Foo = "toString"; Unlike |
@RyanCavanaugh ok. so the same problem with RegExp, Date, ... And now there is inconsistency: |
@jacksteinberg and I have noticed this in a project that is using the TypeScript definitions. We have so far identified the following missing declarations:
In contrast, others overrides of Object.prototype methods are included in the TypeScript definitions, e.g. Number.prototype.toString, Boolean.prototype.valueOf, Array.prototype.toLocaleString. We haven't done an exhaustive search; those were just particular instances of overridden toStrings that we were trying to pick up with our tool (but ended up getting the wrong result due to the missing TypeScript definitions). In particular I wonder if other /cc @saschanaz as someone who has been helpful keeping TypeScript's built-in type definitions up to date in the past. |
Corresponding issue on TSJS-lib-generator: microsoft/TypeScript-DOM-lib-generator#322. The emitter currently does not do anything for We could generate |
I think it'd be best to include toString for the interfaces which have specific toString behavior that differs from Object.prototype. There are not many of those. (I'd guess 5 in the JS spec, 20ish on the web platform.) This already seems to be the policy, e.g. Array.prototype.toString and Number.prototype.toString are included. There are just some that got missed for whatever reason. |
Definitely can be done, but what would be the use cases? Couldn't understand the purpose of jackbsteinberg/get-originals-rewriter#79. |
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. |
because it is JS core feature. |
typescript-eslint/typescript-eslint#4999 hit this in typescript-eslint-land. We take an approach similar to #30225 (comment) the |
TypeScript Version: 3.4.0-dev.20190305
Code
Expected behavior:
keyof Boolean
should be"toString" | "valueOf"
Playground
The text was updated successfully, but these errors were encountered: