Skip to content
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

Generic class-scoped arrow functions lack access to class-level type reflections #2320

Closed
Oblarg opened this issue Jun 28, 2023 · 2 comments
Closed
Labels
bug Functionality does not match expectation help wanted Contributions are especially encouraged

Comments

@Oblarg
Copy link

Oblarg commented Jun 28, 2023

When defining generic class functions whose lower bounds depend on class-level generics, the lower bound types will resolve/expand based on the value of those generics. For example, consider this (very lengthy) string literal union:

image

However, if a similar function is defined with an arrow function, the lower bound does not expand and is instead broadened to just string:

image

The type constraints are identical between these two functions; they differ only in that the former is a class method and the latter is an arrow function.

It would be really nice if the rendering were consistent here.

@Oblarg Oblarg added the bug Functionality does not match expectation label Jun 28, 2023
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jun 29, 2023

Please provide a code snippet that can be used to reproduce this

@Gerrit0 Gerrit0 added the needs reproduction Needs a minimal reproducible case label Jun 29, 2023
@Oblarg
Copy link
Author

Oblarg commented Jun 29, 2023

export type BaseUnionMember = {
    type: string;
}

export type Union =
    {
        type: "one"
    } |
    {
        type: "two"
    }

export class GenericClass<U extends BaseUnionMember> {
    public arrowFunction = <MemberType extends U['type']>(member: Extract<U, { type: MemberType}>) => {

    }

    public classFunction<MemberType extends U['type']>(member: Extract<U, { type: MemberType}>) {

    }
}

export class ResolvedSubclass extends GenericClass<Union> {

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Functionality does not match expectation help wanted Contributions are especially encouraged
Projects
None yet
Development

No branches or pull requests

2 participants