StudyPlayground / TypeScript-Exercise-Challenges

Typescript exercise & challenges
2 stars 0 forks source link

Type Challenges 529-Absolute #50

Open kscory opened 5 months ago

kscory commented 5 months ago

답안을 작성해주세요.

wogha95 commented 4 months ago
bananana0118 commented 4 months ago
type Absolute<T extends number | string | bigint> = `${T}` extends `${infer F}${infer REST}` ? 
                                                      F extends Out ? `${Absolute<REST>}` : `${F}${Absolute<REST>}` : ""

저두요 템플릿러터럴로 형변환해줘야 되더라구요...

bananana0118 commented 4 months ago
  • extends 전에 template literal로 형변환 처음알았습니다,,
type Absolute<T extends number | string | bigint> = `${T}` extends `-${infer U}` ? U : `${T}`;

와우 간단하네요

kscory commented 4 months ago
type Absolute<T extends number | string | bigint> = `${T}` extends `-${infer N}` ? N : `${T}`