microsoft / microsoft/TypeScript
Separate type application from function application
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
As discussed in #28931, currently the type application for the function with generic parameters is tied to that function application.
Specialize the value of the function with generics is only possible during the call. So the following compiles fine:
function id<V> (v : V) { return v }
const some : Date = id<Date>(new Date())
But this does not:
function id<V> (v : V) { return v }
type IdDate = typeof id<Date> // TS1005: ';' expected
const dateId = id<Date> // TS1109: Expression expected.
It would be very beneficial to separate type application from function application. For example (the original reason of this request), it will allow mixins with generic parameters:
export type Constructable<T extends any> = new (...args : any[]) => T
export type AnyFunction = (...input: any[]) => any
export type Mixin<T extends AnyFunction> = InstanceType<ReturnType<T>>
export const Atom = <V, T extends Constructable<Object>>(base : T) =>
class Atom extends base {
value : V
hasValue () : boolean {
return this.hasOwnProperty('value')
}
}
export type Atom = Mixin<typeof Atom> // this currently works, but does not have generic argument
export type Atom<V> = Mixin<typeof Atom<V>> // this is the goal
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the discussion in issue #28931 first, then use the examples here to identify the intended syntax and its interaction with generic functions, type queries, and mixins. Done means the proposed type application can be used independently of a function call and the shown examples compile as intended.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100