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

Emit classes instead of vars #222

Open
saschanaz opened this issue Mar 28, 2017 · 10 comments
Open

Emit classes instead of vars #222

saschanaz opened this issue Mar 28, 2017 · 10 comments

Comments

@saschanaz
Copy link
Contributor

saschanaz commented Mar 28, 2017

Now that we can extend both class instance type and static type, can we now directly emit classes? Is there any remaining blocking problems?

@sufianrhazi
Copy link

The ability to emit classes would help implement my proposed solution to the WebGL declarations' use of empty interfaces: microsoft/TypeScript#5855 (comment)

@saschanaz
Copy link
Contributor Author

I will submit a PR if someone gives Accepting PR tag.

@RReverser
Copy link
Contributor

On the other hand, emitting classes makes it much harder to extend built-in types with optional extensions, since class declarations cannot be merged together, but interfaces can.

@saschanaz
Copy link
Contributor Author

saschanaz commented Dec 17, 2019

class declarations cannot be merged together, but interfaces can.

This works:

declare class Merge {
    x: string;
}

interface Merge {
    y: string;
}

new Merge().y;

It can't extend static properties, but it never worked anyway.

@RReverser
Copy link
Contributor

@saschanaz Yeah I'm trying to fix that right now actually, because ran into a problem with polyfilling static methods :) #812

@RReverser
Copy link
Contributor

To be clear - I came across this issue because I'd also be happy if there was a way to reduce all that clutter and just use class, but polyfilling is quite important for Web APIs, and not being able to do it seems like a dealbreaker.

Hopefully this can be somehow fixed on TypeScript side in the future by allowing merging classes with classes, or adding static methods to interfaces or something similar.

@saschanaz
Copy link
Contributor Author

There is a relevant issue on TS: microsoft/TypeScript#2957

@RReverser
Copy link
Contributor

Actually... I've just realised that something like this might work for extending statics:

declare class Merge {
    x: string;
    static X: string;
}

interface Merge {
    y: string;
}

declare namespace Merge {
    const Y: string;
}

new Merge().x;
new Merge().y;
Merge.X;
Merge.Y;

So if we implement this, then #812 would be unnecessary.

Either option is fine by me and better than current status quo that doesn't allow any extensions, but this one would probably be even cleaner.

@RReverser
Copy link
Contributor

FWIW - just so that our work doesn't conflict - I'm giving this a try.

@RReverser
Copy link
Contributor

Update: I have a working implementation of this, but waiting for #813 to be merged first.

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