Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate type application from function application #29043

Open
canonic-epicure opened this issue Dec 15, 2018 · 4 comments
Open

Separate type application from function application #29043

canonic-epicure opened this issue Dec 15, 2018 · 4 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@canonic-epicure
Copy link

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
@weswigham weswigham added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Dec 17, 2018
@canonic-epicure
Copy link
Author

Any hope for this feature? I think it will unblock many other advanced use cases.

@canonic-epicure
Copy link
Author

Any hope for a proper solution? Having a generic argument for a mixin function is a very common requirement.

@bennypowers
Copy link

Checking in to see if this is on the radar

@joshuambg
Copy link

Please and thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants