Improve error message on indexed access to private members of type parameters#31942
Improve error message on indexed access to private members of type parameters#31942andrewbranch merged 3 commits intomicrosoft:masterfrom
Conversation
The type of the private is erased in a declaration file, so the index will become export class A {
private a: string;
}
export type X<T extends A> = T["a"];emitted with declarations becomes export class A {
private a;
}
export type X<T extends A> = T["a"];wherein So yeah, there is a reason we can't allow accessing privates on generics - since we need to defer resolving the type and we know that the type information for privates is erased, the type information for the privates of generics can't be considered constant. |
|
Ah, ok. So the observable effect of this problem is that you’d have different results depending on whether you were consuming this type as a |
|
@weswigham I reverted my previous change and am issuing a more specific error message instead now—thanks for the explanation. |
weswigham
left a comment
There was a problem hiding this comment.
I'd edit the PR title and OP just for ease of browsing the repo history, too.
|
Oh, I edited the title but forgot about the original post. Thanks! |
Fixes #30882, assuming it's a bug. Noticing that this works (has always worked?):I assumed that there’s no reason why the same shouldn’t work whenAis the constraint of a type parameter:EDIT: #30882 is not a bug, as @weswigham explains below. This PR now just improves the error message.