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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Narrow doesn't work on template literal types #257

Open
DetachHead opened this issue Oct 15, 2021 · 1 comment
Open

Narrow doesn't work on template literal types #257

DetachHead opened this issue Oct 15, 2021 · 1 comment

Comments

@DetachHead
Copy link

馃悶 Bug Report

Reproduce the bug

declare const foo: <T extends number>(value: Narrow<`${T}`>) => void

foo('12')

Screenshots

image

Additional context

trying to make a toNumber function that knows the value at compiletime

const toNumber = <T extends number>(value: Narrow<`${T}`>): T => Number(value) as T

const value: 12 = toNumber('12') //TS2322: Type 'number' is not assignable to type '12'.
@DetachHead
Copy link
Author

may be a limitation in the compiler related to microsoft/TypeScript#42938

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant