-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptIn DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Bug Report
π Search Terms
string constructor number type template literal
π Version & Regression Information
4.2.3
β― Playground Link
Playground link with relevant code
π» Code
const stringNumber: `${number}` = String(123)π Actual behavior
Error: Type 'string' is not assignable to type '${number}'.(2322)
π Expected behavior
No error.
Why
String, according to ES (String(value), and ToString(argument)), uses toString method on passed in values, so ideally the fix should include only changes on Number interface, but currently it's String's def does not care about toString, so these two signature would have to be generic:
// lib.es5.d.ts
interface StringConstructor {
new(value?: any): String;
(value?: any): string;
}And this one would need to be generic as well as the type of returned string would depend on the radix.
// lib.es5.d.ts
interface Number {
toString(radix?: number): string;
}This approach would make String easily extensible and compatible with template literal types, but I'm not sure how drastic of a change it is.
Most likely would be related to #42996
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptIn DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript