Skip to content

The type of private fields in a class cannot be used in generic #30882

@worudso

Description

@worudso

TypeScript Version: 3.4.1

Search Terms:
generic, class, private field
Code

class Foo<T> {
    private a!: T; // when it is public, no error occurs below
}

type Bar<T extends Record<string, Foo<any>>> = T[keyof T]["a"]; // ts(2536) occurs, while autocomplete works well.
type A = Foo<number>["a"]; // it works always!

Expected behavior:
Not treating it as an error. If it is inteneded, at least the error message should be more helpful.
Actual behavior:
ts(2536) occurs.
Playground Link
Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions