Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

JonghwanWon
Copy link
Contributor

This PR updates typescript.md to Adds a few extra hints.

@ShivamJoker
Copy link

Good work

Comment on lines 254 to 264
```ts
type GetReturnType<T> = T extends (...args: unknown[]) => infer R
? R
: never;

type Num = GetReturnType<() => number>; // number

type First<T extends Array<any>> = T extends [infer F, ...infer Rest] ? F : never;

type Str = First<['hello', 1, false]>; // 'hello'
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those are two different examples. You may split those.

type GetReturnType<T> = T extends (...args: unknown[]) => infer R
  ? R
  : never;

type Num = GetReturnType<() => number>; // number
type First<T extends Array<any>> = T extends [infer F, ...infer Rest] ? F : never;

type Str = First<['hello', 1, false]>; // 'hello'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.
I fixed it.

@rstacruz rstacruz merged commit 6999e94 into rstacruz:master Oct 27, 2022
@JonghwanWon JonghwanWon deleted the typescript branch October 29, 2022 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants