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

Any plans to implement generics or typescript utilities? #19

Open
dwjohnston opened this issue Nov 14, 2019 · 4 comments
Open

Any plans to implement generics or typescript utilities? #19

dwjohnston opened this issue Nov 14, 2019 · 4 comments

Comments

@dwjohnston
Copy link

I'm wanting to do something like this:

interface Foo {
    id: string; 
    biz: string; 
    bar: string; 
}

type PartialFoo = Pick<Foo, "id" | "biz">; 

Pretty simple.

But the compiler will give me:

Error: Generics are not yet supported by ts-interface-builder:

Is there any plan to incorporate this support?

@dwjohnston
Copy link
Author

dwjohnston commented Nov 14, 2019

Hmmm, looking at the code, it looks like it might be easy enough to support some of the basic utility types. If I get some time, I'll see if I can do it.

} else if (node.typeName.getText() === "Promise") {

@dsagal
Copy link
Member

dsagal commented Nov 14, 2019

Implementing specific generics like Pick seems reasonably straightforward. Implementing generics generally (or even just mapped types generally) is probably doable too, but requires a much deeper understanding of typescript internals.

@xzilja
Copy link

xzilja commented Mar 25, 2021

I'd like to try and implement support for few generic types that I am using i.e. Pick Omit Partial NonNullable and so on. Could you briefly explain where / how this should be done so I can give it a go?

@dsagal
Copy link
Member

dsagal commented Mar 25, 2021

There are two generic types handled: Array<T> and Promise<T> (the latter is just treated as T, which happens to be helpful for some cases). See _compileTypeReferenceNode method. That's where the processing would start, I imagine.

As for how to process it, it would be nice to do something that could extend to generics more generally later. E.g. translate Pick<T> maybe to t.instance('Pick', 'T'), and add support on ts-interface-checker side, which recognizes a few names of generics, looks up the type object for the type argument(s), and does something custom to turn those type objects into new ones.

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

No branches or pull requests

3 participants