Skip to content

Make an example more illustrative in Generics.md - #2988

Merged
Jake Bailey (jakebailey) merged 1 commit into
microsoft:v2from
grebenyuksv:patch-2
Jun 5, 2024
Merged

Make an example more illustrative in Generics.md#2988
Jake Bailey (jakebailey) merged 1 commit into
microsoft:v2from
grebenyuksv:patch-2

Conversation

@grebenyuksv

@grebenyuksv grebenyuksv commented Dec 3, 2023

Copy link
Copy Markdown
Contributor

When reading this, I thought the authors' idea must have been to use different names in the generic type parameter and the type. Doesn't the suggested version illustrate the concept better? 🤔

We could also have used a different name for the generic type parameter in the type, so long as the number of type variables and how the type variables are used line up.

Before
The name is Input in both declarations:

function identity<Input>(arg: Input): Input {
  return arg;
}

let myIdentity: <Input>(arg: Input) => Input = identity;

After
The name is Type in the first declaration but Input in the second:

function identity<Type>(arg: Type): Type {
  return arg;
}

let myIdentity: <Input>(arg: Input) => Input = identity;

I don't think this PR suggests anything new — I rather believe the suggested version was the original intention.

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.

2 participants