-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Compiler does not allow abstract generators #25710
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
Comments
Why is this necessary? The asterisk here is just syntactic sugar for the return type: abstract class SomethingAbstract {
abstract sadGenerator(): IterableIterator<any>;
} If the extending class implements the method as generator or just returns an IterableIterator is an implementation detail. |
That's true. However, I think the inconsistency inandofitself in the behavior is a problem: if we allow abstract generators, we should allow them to be written with generator syntax, sugar or not. |
TypeScript does allow abstract |
We don't allow abstract class C {
async abstract m(): Promise<number>; // OK?
}
interface I {
async m(): Promise<number>; // Error
}
type T = { async m(): Promise<number>; } // Error
type Cb = async () => Promise<number>; // Error |
@Andy-MS right, it looks like |
Out of curiosity, what's the rationale for not allowing If the consensus is to make |
I do not think the original issue is a bug. generators, just like I do agree with @Andy-MS' comment that |
@mhegazy Sounds good! Should I open an issue about |
sure. |
How should this be implemented in a concrete class? Currently, abstract class A {
public abstract m(): IterableIterator<string>;
}
class C implements A {
public *m() {
yield 'foo';
}
} Has the error, |
@dyst5422 I don't see any such error when trying to compile that example code in either |
I think this was a file reference issue. Unrelated |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Is it possible to revive this issue by a suggestion that simply allow this ?
Error: I'm currently using a workaround with:
|
This was a breaking change as of TS 4.x: microsoft/TypeScript#39963 More context: microsoft/TypeScript#25710 (comment)
* Bumped TypeScript version to 4.1.3 * Removed async modifier from abstract method This was a breaking change as of TS 4.x: microsoft/TypeScript#39963 More context: microsoft/TypeScript#25710 (comment) * Removed ts-node from non-root package.json files * Added test:sdk script to root package.json * Fixed specConverter paths * Fixed logical error in declarationMiner.spec.ts * yarn.lock * Fix root path resolution for sdk-rtl testUtils.ts Co-authored-by: John Kaster <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
TypeScript Version: First noticed on 2.9.1, confirmed in 3.0.0-dev.20180712
Search Terms:
generator abstract, "An overload signature cannot be declared as a generator.", generator overload, overload generator abstract, TS1222
Code
Expected behavior:
The compiler should allow abstract generator methods.
Actual behavior:
The compiler does not allow abstract generator methods: instead, it errors with:
[ts] An overload signature cannot be declared as a generator.
I believe I know where and why this is and I'll open up a PR once I fix it.
Playground Link: Small sample
Related Issues:
Couldn't find any related ones
The text was updated successfully, but these errors were encountered: