-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
⚙ Compilation target
esnext
⚙ Library
esnext
Missing / Incorrect Definition
NumberConstructor(value?: any): number
:
Lines 570 to 572 in 261630d
interface NumberConstructor { | |
new (value?: any): Number; | |
(value?: any): number; |
This is correct but I think could be improved to work better when converting string literals to numbers by returning number literals. This could be achieved by doing something like
<T>(value?: T): T extends `${infer N extends number}` ? N : number;
Sample Code
const A = "12";
const B: 12 = Number(A); // Type 'number' is not assignable to type '12'.
const A2: "12" | "13" | "14" = "12";
const B2: 12 | 13 | 14 = Number(A2); // Type 'number' is not assignable to type '12 | 13 | 14'.
Documentation Link
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/Number
kirkwaiblinger
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript