basarat / basarat/typescript-book
Generic instantiation
- Dominant language
- TypeScript
- Stars
- 21.6k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
In type space using `type` e.g.
```ts
type Foo = {foo: T}
type Bar = Foo;
```
In variables space (investigating):
```ts
// A function that takes argument of type `T`
// And returns an object of type `{foo:T}`
const foo = (x: T) => ({ foo: x });
// Instantiate `T` as number in a variable bar
const bar = foo; // Error: Invalid syntax
```
Contributor guide
Research direction
Start with the generic function and variable-space examples in the issue, then review the TypeScript book’s existing guidance on generic functions and type aliases. Determine whether the requested instantiation form is supported and document the correct explanation or limitation, with an example that resolves the reported syntax error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100