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

300 - String to Number #26832

Open
Acoooooooer opened this issue Apr 25, 2023 · 0 comments
Open

300 - String to Number #26832

Acoooooooer opened this issue Apr 25, 2023 · 0 comments
Labels
300 answer Share answers/solutions to a question zh-CN 简体中文

Comments

@Acoooooooer
Copy link

Acoooooooer commented Apr 25, 2023

type Num = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]

type FuNum<S> = S extends `-${infer R}` ? R : S
type isFu<S> = FuNum<S> extends never ? S : FuNum<S>

type isNum<S> = S extends `${infer R}${infer X}`
  ?
  (R extends `${Num[number]}`
    ?
    (X extends '' ? true : isNum<X>)
    : false)
  : never

type GetNum<S> = isNum<isFu<S>> extends true ? S : never

type A<S, Arr extends any[] = []> = S extends `${Arr['length']}` ? Arr['length'] : A<S, [S, ...Arr]>

type ToNumber<S extends string> = A<FuNum<GetNum<S>>>



// this's  false         (  +number  To  -number  ,    i  don't  konw     HELP ME!    )
 Expect<Equal<ToNumber<'-27'>, -27>>
@Acoooooooer Acoooooooer added answer Share answers/solutions to a question zh-CN 简体中文 labels Apr 25, 2023
@github-actions github-actions bot added the 300 label Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
300 answer Share answers/solutions to a question zh-CN 简体中文
Projects
None yet
Development

No branches or pull requests

1 participant