Skip to content

Conversation

@tvogel
Copy link

@tvogel tvogel commented Feb 15, 2023

For newbies like me that read the manual start-to-end to get an introduction into the concepts, the appearance of never[] here is surprising, inexplicable and confusing. So, I was very happy about the thorough explanation linked in this commit.

For newbies like me that read the manual start-to-end to get an introduction into the concepts, the appearance of `never[]` here is surprising, inexplicable and confusing. So, I was very happy about the thorough explanation linked in this commit.
@tvogel
Copy link
Author

tvogel commented Apr 15, 2023

Ping - anybody out there?

@tvogel
Copy link
Author

tvogel commented May 9, 2023

@andrewbranch Is this of interest?

type Bools = GetReturnType<(a: boolean, b: boolean) => boolean[]>;
// ^?
```
If you are curious about the use of `never[]` as the most generic type for function arguments, there is an excellent explanation in this [reddit](https://www.reddit.com/r/typescript/comments/muyl55/comment/gv9ndij/?utm_source=reddit&utm_medium=web2x&context=3).
Copy link
Member

Choose a reason for hiding this comment

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

I think that we probably need an explainer about this, but I don't think that this wording or a link to reddit is appropriate. Note that TS 5.0 greatly refined the type relationship between the different function "top types" such that this answer may not longer be accurate. Though the end result of "you probably want never[]" may still apply.

Related PR: microsoft/TypeScript#52282

Copy link
Member

Choose a reason for hiding this comment

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

Honestly, I think the example should replace never[] with any[]. We try to avoid having to include these “by the way did you know about this very confusing thing???” asides in the handbook specifically. An explainer might be better suited in the reference pages of the docs, but I don’t know if there’s any existing content where it would make sense to slot in.

Copy link
Member

Choose a reason for hiding this comment

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

I did some sleuthing to figure out the origin of this; it seems like this has been there since the beginning of the new handbook in microsoft/TypeScript-New-Handbook@1a21a7f; @DanielRosenwasser do you have an opinion on this one?

Choose a reason for hiding this comment

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

I think that any[] should be sufficient for the purposes of this example, especially since we use any[] in the definition of Flatten<T> further up on the same page.

type Bools = GetReturnType<(a: boolean, b: boolean) => boolean[]>;
// ^?
```
If you are curious about the use of `never[]` as the most generic type for function arguments, there is an excellent explanation in this [reddit](https://www.reddit.com/r/typescript/comments/muyl55/comment/gv9ndij/?utm_source=reddit&utm_medium=web2x&context=3).
Copy link
Member

Choose a reason for hiding this comment

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

Honestly, I think the example should replace never[] with any[]. We try to avoid having to include these “by the way did you know about this very confusing thing???” asides in the handbook specifically. An explainer might be better suited in the reference pages of the docs, but I don’t know if there’s any existing content where it would make sense to slot in.

@jakebailey jakebailey closed this Jun 5, 2024
@jakebailey jakebailey reopened this Jun 5, 2024
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

Successfully merging this pull request may close these issues.

4 participants