-
Notifications
You must be signed in to change notification settings - Fork 201
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
Support getters in interfaces #4961
Comments
+1 In addition to this change, I think we should evaluate the purpose of structs. In terms of type expressiveness, this change makes structs a subset of interfaces. structs no longer serve a purpose that can't be solved by the compiler itself. Why not get rid of structs and support interfaces everywhere structs are used i.e.:
If the concern is "structs are special because they provide a guarantee of no functions/behavior", I would say:
|
mmmm. not sure I recall to be honest. i don't have any problem with it.
there's a fundamental difference between behavioral interfaces and data structures in my mind. i don't think structs and interfaces are the same thing. for example, happy to discuss more, but probably not over this issue... |
@eladb, @Chriscbr , @MarkMcCulloh - do you know if JSII supports interface fields? |
yes, it is supported. |
Option 1:
Option 2:
|
I like the idea of some syntax for specifying if the field is set-able or not, it could be a useful API design tool. |
Should we use the typescript notation What would be the syntax for setters? get set foo: str; or: get foo(): str;
set foo(x: str): void; |
For inspiration, here's how Swift approaches it https://docs.swift.org/swift-book/documentation/the-swift-programming-language/protocols#Property-Requirements Of the two options you mentioned @eladb I like the first one better since I don't have to type the field name twice. How does a user add computed properties to a class? |
Maybe like in TypeScript: class MyClass {
get value(): num {
return 12;
}
set value(v: num) {
log("setting value to {v}");
} But there's something a bit weird about the difference between declarations in interfaces and definitions in classes, no? |
Let's avoid bike shedding and just go with the typescript syntax for now. I think it's pretty solid. Updated summary. |
Hi, This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. |
I think I ran into this issue while trying to implement #6412. I exposed an inflight interface in the SDK for an AWS Lambda Context Object in the SDK (see ILambdaContext in e9fe251), but the compiler panics with a message "No support for inflight properties yet" when type checking it. I think I might be able to work around this case by making them methods and adding some more wrapper code, but support for inflight properties would make a big difference here. |
Feature Spec
Wing interfaces now support fields.
For now, let’s only support
get
properties.When an interface is implemented by a class, properties can be implemented using fields:
In the future we will support defining properties on classes as well and then they can also be used as an implementation of getters in interfaces.
Use Cases
API design tools
Implementation Notes
No response
Component
Compiler
Community Notes
The text was updated successfully, but these errors were encountered: