Typescript: Question: TypeScript and proposal-first-class-protocols

Created on 28 Sep 2017  路  5Comments  路  Source: microsoft/TypeScript

Now proposal-first-class-protocols become stage-1.
TypeScript team track and collaborate this proposal?
This proposal looks like conflict with typescript interface implementation.

I think It's more intuitive to replace interface to protocol in future.
Yes I know this proposal is now stage-1, but I want to know TypeScript-Team how think of about this proposals ?

Discussion

Most helpful comment

Note that even if protocols land, interface and protocol will remain different things and interface will still be useful (e.g. for describing an extensible type which has a particular shape, and especially for type definitions)鈥攅ven if some of the scenarios to which interfaces are currently put will be expressible via protocols.

(To be clear: I say this as someone who couldn't possibly be more excited about protocols. I want them yesterday.)

All 5 comments

Note that even if protocols land, interface and protocol will remain different things and interface will still be useful (e.g. for describing an extensible type which has a particular shape, and especially for type definitions)鈥攅ven if some of the scenarios to which interfaces are currently put will be expressible via protocols.

(To be clear: I say this as someone who couldn't possibly be more excited about protocols. I want them yesterday.)

Yes, I think like classes imply interfaces (two actually), protocol will also imply a specific interface and doesn't supplant interface or type. If adopted, it maybe real world code would use less interface, but as noted, protocol will be a concrete, immutable type once declared, which is contrary to the open ended nature of interface.

@chriskrycho @kitsonk
Thank you for your views, and I misunderstood about this proposals.
I see detail of that proposal one more time, It's not a simple protocol, it's symbol collections that has implementations.
So it's not become interface, and my view of interface and protocol is not suitable to this proposals.
But, If protocol has landed, protocol typed as like Protocol ?

protocol Foo {
  symbol_1,
  symbol_2,
  defaultImpl() { return 1; }
}
// Foo = Protocol<{
//  symbol_1: symbol,
//  symbol_2: symbol,
//  defaultImpl(): number;
// }>

@brn that sounds related to the work in #15473.

@aluanhaddad Thank you for reference.
You have a point. That PR will help protocol implementation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wmaurer picture wmaurer  路  3Comments

kyasbal-1994 picture kyasbal-1994  路  3Comments

manekinekko picture manekinekko  路  3Comments

DanielRosenwasser picture DanielRosenwasser  路  3Comments

MartynasZilinskas picture MartynasZilinskas  路  3Comments