Skip to content

ParseInteger and ParseBoolean #449

Open
@sindresorhus

Description

@sindresorhus

Would it be useful to be able to convert a number in a string to a number literal type? '100' => 100.

I guess a more strictly typed Number.parseInt could take advantage of this.

type SomeNum = "100" extends `${infer U extends number}` ? U : never;
// 100

We cannot do ParseNumber because if it doesn't match exactly, it just returns a number type instead of 100:

type SomeNum = "100.0" extends `${infer U extends number}` ? U : never;
// number

We could also maybe do ParseBoolean and maybe Is methods too (IsInteger)?

Maybe it's not that useful. Feedback wanted.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions