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

Spec inconsistency for type aliases #17287

Closed
impworks opened this issue Jul 19, 2017 · 6 comments
Closed

Spec inconsistency for type aliases #17287

impworks opened this issue Jul 19, 2017 · 6 comments
Assignees
Labels
Spec Issues related to the TypeScript language specification

Comments

@impworks
Copy link

Specification, chapter 3.10:

An interface can be named in an extends or implements clause, but a type alias for an object type literal cannot.

This contradicts the actual behaviour seen in current Playground:

  • Interface cannot be used in the extends clause
  • Type alias can be used in the implements clause as well as an interface
@olegdunkan
Copy link

olegdunkan commented Jul 19, 2017

Interface cannot be used in the extends clause

It can

interface A { x:number;}
interface B  extends A { y:number;}

Type alias can be used in the implements clause as well as an interface

Now it is true.

Spec now is in stale state.

@impworks
Copy link
Author

You're right. I meant the extends clause for a class definition.
The following line is also misleading:

since interface types offer more capabilities they are generally preferred to type aliases

  • The type syntax supports mapped types, while interfaces do not
  • There's no way to emulate A | B using interfaces (or is there?)

Spec now is in stale state.

So is the spec going to be updated, or it is abandoned for the sake of faster development?

@ikatyang
Copy link
Contributor

So is the spec going to be updated, or it is abandoned for the sake of faster development?

See #17215 (comment)

@olegdunkan
Copy link

since interface types offer more capabilities they are generally preferred to type aliases

Type alias is like named references to any kind of type (primitive types, object types, union types, intersection types, mapped types), interface is like named reference to object type. You can't extend (in the sense of adding extensions to the existed class) class with an alias but with an interface can. Declaration merging is working for interfaces (class and interface, interface and interface) and enums, namespaces.

import {A} from "./a"

declare module './i' {
  interface A {
    f2():void;
  }
}

A.prototype.fn2 = function() {

};

By the way, spec doesn't contain that.

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Spec Issues related to the TypeScript language specification labels Jul 20, 2017
@DanielRosenwasser DanielRosenwasser self-assigned this Jul 20, 2017
@DanielRosenwasser
Copy link
Member

I believe this was a change we made where if a type reference resolves to an object type, then you can use it in an implements clause.

Thanks for reporting!

@mhegazy mhegazy removed the Bug A bug in TypeScript label Aug 31, 2017
@DanielRosenwasser DanielRosenwasser changed the title Spec inconsistensy for type aliases Spec inconsistency for type aliases Nov 15, 2017
@RyanCavanaugh
Copy link
Member

The spec is now an "archived" artifact and we won't be tracking defects against it anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Spec Issues related to the TypeScript language specification
Projects
None yet
Development

No branches or pull requests

6 participants