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

fix typeof import("path").Foo.#private #48763

Closed
wants to merge 1 commit into from

Conversation

magic-akari
Copy link
Contributor

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Apr 19, 2022
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'.
Copy link

@nicolo-ribaudo nicolo-ribaudo Apr 20, 2022

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.

Copy link
Contributor Author

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)

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the precedence, that's #19707 (mentioned in #48640). All of this is getting really hairy and inconsistent, though.

Copy link
Contributor Author

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.

@magic-akari
Copy link
Contributor Author

#47696 is reverted by #48959, so I close this for now.

@magic-akari magic-akari closed this May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

typeof on #private Fields not handled by typeof import()
4 participants