-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 computed class properties #2286
Comments
@thejameskyle anything on this yet ? |
@git-jiby-me Not yet, we'll update the issue when progress has been made |
As this still isn't fixed, does anyone have a workaround? I want to make an iterable class like this: class Foo {
[Symbol.iterator]() {
// ...
}
} Is there any way to do it? |
@callumlocke something like this: class Foo {
constructor() {
(this: any)[Symbol.iterator] = this._iterator;
}
_iterator(): Iterator<number> {
return (function *() {
yield 1;
yield 2;
yield 3;
}())
}
@@iterator(): Iterator<number> {
throw new Error();
}
} |
it's a bit annoying, but if you use |
In that case you can escape it using comments: class Foo {
constructor() {
(this: any)[Symbol.iterator] = this._iterator;
}
_iterator(): Iterator<number> {
return (function *() {
yield 1;
yield 2;
yield 3;
}())
}
/*::
@@iterator(): Iterator<number> {
throw new Error();
}
*/
} |
On a related note, does anyone have a work-around that would allow me to create an if (isIterable(val)) {
// Flow should know that `val` has type `Iterable<T>` on this branch of the guard
}
else {
// Vs type `T` on this branch of the guard
} doesn't work when const isIterable = <T> (obj: T | Iterable<T>): boolean =>
typeof (obj: any)[Symbol.iterator] === 'function'; Any smart ideas? |
computed properties would be needed for symbol property keys. // for sequelize...
declare opaque type And = symbol;
declare opaque type Or = symbol;
declare interface WhereLogic {
[And]?: WhereLogic,
[Or]?: Array<WhereLogic>,
[field: string]: any,
} |
Would be useful for |
Computed properties in objects were added (#252), but computed properties in classes are still unsupported.
The text was updated successfully, but these errors were encountered: