Skip to content

Class expressions should support in and out variance modifiers #48618

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

Closed
DanielRosenwasser opened this issue Apr 9, 2022 · 2 comments · Fixed by #48645
Closed

Class expressions should support in and out variance modifiers #48618

DanielRosenwasser opened this issue Apr 9, 2022 · 2 comments · Fixed by #48645
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@DanielRosenwasser
Copy link
Member

Likely an oversight but

let Anon = class <out T> {
    foo(): InstanceType<(typeof Anon<T>)> {
        return this;
    }
}

let OuterC = class C<out T> {
    foo(): C<T> {
        return this;
    }
}

Results in the following message:

error! 'out' modifier can only appear on a type parameter of a class, interface or type alias
@ahejlsberg
Copy link
Member

Yup, that's an oversight.

@ahejlsberg ahejlsberg self-assigned this Apr 11, 2022
@ahejlsberg ahejlsberg added this to the TypeScript 4.7.1 milestone Apr 11, 2022
@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Apr 11, 2022
@DanielRosenwasser DanielRosenwasser changed the title Should class expressions support in and out variance modifiers? Class expressions should support in and out variance modifiers Apr 11, 2022
@ahejlsberg
Copy link
Member

ahejlsberg commented Apr 11, 2022

The repro actually reveals another problem: Validation of variance annotations needs to be deferred as it may otherwise cause circularity errors. Indeed, the Anon example errors if validation isn't deferred. I'll put up a PR that fixes both of these issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants