-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Proposal: Introduce a new way to define "inherited" interfaces: likes #18762
Comments
Interfaces are not unique to TypeScript. Are there any other similar language features in other languages that do this that you can point to? |
I have no idea about it. |
I am not a member of the core team. My opinions are my own. I am just raising the question that something like this is far more likely to progress if there is a) established concepts in other languages that can be used as a guideline and b) that there is a syntactical and lexical precedent that can be drawn on. You clearly feel strong about it. If there are features in other languages that align to this, it maybe worth researching that and referencing that to further your proposal. |
Oh.. okay, I'll keep waiting for community responses, I hope this can be a
productive tool for us.
…On Tue, Sep 26, 2017, 18:53 Kitson Kelly ***@***.***> wrote:
So is this cannot be considered? :(
I am not a member of the core team. My opinions are my own. I am just
raising the question that something like this is far more likely to
progress if there is a) established concepts in other languages that can be
used as a guideline and b) that there is a syntactical and lexical
precedent that can be drawn on.
You clearly feel strong about it. If there are features in other languages
that align to this, it maybe worth researching that and referencing that to
further your proposal.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#18762 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFJBfzUIzk2bXoaOmogxCoULafK6HoJtks5smNepgaJpZM4Pj8q5>
.
|
Possibly this could be done with #4183? Subtract out the properties you don't want, then extend that. |
Oh I found this #10727 type NewItem = {...Item, notWanted: undefined, overwrite: NewType } |
See #10727, that proposal is more expressive and more nature than mine. Thanks |
If anyone has interest in this proposal, please let me know, I may do more future work (like try to implement it)
Sometimes, we need a way to introduce an interface that is incompatible with original type but very likes to the original type.
For example, in node-canvas package, they provide a class
Canvas
that very likes to theHTMLCanvasElement
, but it is not compatible withHTMLCanvasElement
. If we can have a clear way to "clone" an interface and make some changes, we can just use this way instead of copy-paste everything in the original type.Proposal: Introduce a new way to define "inherited" interfaces:
likes
Changes to the grammar
Change
InterfaceDeclaration
to:interface BindingIdentifier TypeParameters(opt) InterfaceLikesClause(opt) InterfaceExtendsClause (opt) ObjectType
Add
InterfaceLikesClause
:likes ClassOrInterfaceTypeList
Why to introduce this?
name
is incompatible withPerson
, I can treat it as a little different type ofPerson
)Why not to introduce this?
likes
likes
is a variable name or a keyword.When to use it
HTMLCanvasElement
) but you really want to "extends" from it.When not to use it
ISth['name']
)HTMLElement
also appears on yourFakeElement
, you need a copy-paste )A
andB
and they have logically inherited(or whatever) relationship. ( You should find something common, make it intoC
, and letA
andB
extends fromC
)extends
)Way to generate new type
Need to be precise
Now we get interface extended_liked
Deal with confliction
3.a If anything with the same name is not compatible in A and B, check if it is defined in E, if not, throw an Error ( Property X in C and D is not compatible and also not defined in the interface body, cannot determine which one to use )
3.b If anything with the same name is not compatible in A and B, make this property as type
A.X | B.X
For example:
3.a
3.b
Others
What if I want to remove a property inherited by
likes
?I have 2 ideas at present
If anyone has interest in this proposal, I will consider it later.
When will a liked interface compatible with the original interface?
Just treat it as an another identical normal interface.
Does it breaks the type system?
I don't think so. It is not a subtype of the original type.
What about generics work with proposal?
No idea, I will think it later.
The text was updated successfully, but these errors were encountered: