-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
fix typeof import("path").Foo.#private
#48763
Conversation
static #m = 1; | ||
static #f(x: typeof import("./lib").Bar.#m) {} | ||
~~ | ||
!!! error TS2694: Namespace '"tests/cases/conformance/classes/members/privateNames/lib".Bar' has no exported member '#m'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error seems to be wrong, since Bar
is Foo
and thus it has the #m
static field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't tell if it's completely correct or not.
In this PR, I convert SyntaxError into TypeError.
Maybe it should be counted as "external" access.
According to the latest nightly for TS,
import(..).X.#priv
is technically syntactically valid, but it will never be semantically valid because it counts as "external" access to the private member, which is disallowed.
...
Originally posted by @bradzacher in babel/babel#14454 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will try to add more test cases to determine which case is more reasonable and self-consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a comparable way to test this would be to stick private
onto the non-#
one and see what happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a comparable way to test this would be to stick
private
onto the non-#
one and see what happens.
I didn't manage to do it.
At first I tried to alias type Bar = typeof import("./lib").Bar
, then I found I cannot use Bar.#m
.
typeof import("./lib").Bar.#m
does not imply (typeof import("./lib").Bar).#m
.
it means typeof (import("./lib").Bar.#m)
.
What do you think about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For private
, I just meant to write something like:
// @strict: true
// @target: esnext
// @filename: main.ts
export class Foo {
private static m = 1;
static #f(x: typeof import("./lib").Bar.m) {}
}
// @filename: lib.ts
export { Foo as Bar } from "./main";
Where the static thing is "private" via TS, not via ECMAScript's private identifiers. I was replying on my phone so couldn't write it myself, sorry about that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AST should be changed. This PR is blocked by #48640.
typeof import()
#48690