Skip to content
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

Missing Boolean.toString definition and loose valueOf definition #60517

Open
Akindin opened this issue Nov 16, 2024 · 1 comment
Open

Missing Boolean.toString definition and loose valueOf definition #60517

Akindin opened this issue Nov 16, 2024 · 1 comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@Akindin
Copy link

Akindin commented Nov 16, 2024

⚙ Compilation target

ES2017

⚙ Library

lib.es5.d.ts

Missing / Incorrect Definition

interface Boolean {
    toString<T extends boolean>(this: T): `${T}`
    toString(this: Boolean): `${boolean}`
    valueOf<T extends boolean>(this: T): T
    valueOf(this: Boolean): boolean
}

TS Playground

Related issues #30225, #38347

Sample Code

const bool = true as boolean;


let a: `${boolean}` = true.toString();
let b: `${boolean}` = false.toString();
let c: `${boolean}` = bool.toString();
let d: `${boolean}` = new Boolean().toString();
let e: `${boolean}` = Boolean().toString();

let f: true = true.valueOf();
let g: false = false.valueOf();

Documentation Link

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/toString
https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-boolean.prototype.tostring
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf
https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-boolean.prototype.valueof

@jcalz
Copy link
Contributor

jcalz commented Nov 16, 2024

new Boolean().toString() and true.valueOf() make me want to cry. Is there any real world example that couldn't be served equally well by just "false" or `${false}` as const or, for valueOf, just, like... true? Why would the suggested modification be a good idea for all TS code everywhere and not just merged as-needed for those who want it?

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants