DEV Community

Discussion on: Advanced TypeScript Exercises - Answer 7

Collapse
 
jrumandal profile image
John Ralph Umandal

**palmface** I was strictly trying to touch only the line of function takeSomeTypeOnly.

These challenges are really nice, but please be specific with what we can and cannot do. D:

// change below function type definition 🔥 in order to allow only strict SomeType value
I might be the one misunderstanding.

Thanks anyway! Your exercises keep my brain running

Collapse
 
macsikora profile image
Pragmatic Maciej

Thanks for the comment. Sorry if smth was not clear.

Collapse
 
alextsk profile image
alextsk

you can do it in one line

function takeSomeTypeOnly<T extends SomeType>(x: SomeType extends T ? T : never)
  { return x }
Enter fullscreen mode Exit fullscreen mode
Collapse
 
arthurka profile image
ArthurKa

Nice try. Don't work.

const x2 = { prop: 'a' } as const;
takeSomeTypeOnly(x2);
Enter fullscreen mode Exit fullscreen mode