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

typeof on #private Fields not handled by typeof import() #48690

Closed
magic-akari opened this issue Apr 14, 2022 · 2 comments
Closed

typeof on #private Fields not handled by typeof import() #48690

magic-akari opened this issue Apr 14, 2022 · 2 comments
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@magic-akari
Copy link
Contributor

magic-akari commented Apr 14, 2022

Bug Report

Can you add a new test case?

// a.ts
export class Foo {
  static #p;
  m(param: typeof import("./b").#p) {} 
}
// b.ts
export { Foo as default } from "./a"

The syntax should be valid.

Originally posted by @JLHwung in babel/babel#14454 (review)

Oh I misunderstood typeof import("./foo") before: I thought it was like js import() but it turns out to be actually a dynamic namespace import. So to make type checker happy, we can

// privateNameInTypeQueryImport.ts
export declare class Foo {
    static #p;
    m(p: typeof import("privateNameInTypeQueryImportLib").Foo.#p): any;
}
// privateNameInTypeQueryImportLib.ts
export { Foo } from "./privateNameInTypeQueryImport"

Originally posted by @JLHwung in babel/babel#14454 (comment)

I'm not sure if typeof import('path').#p is valid syntax, but I think typeof import('path').Foo.#p is.

🔎 Search Terms

  • typeof on #private Fields
  • typeof import

🕗 Version & Regression Information

  • This is new feature in TypeScript 4.7 Beta

⏯ Playground Link

Playground link with relevant code

💻 Code

// @filename: main.ts
export class Foo {
  static #m = 1;
  static #f(x: typeof import("./lib").Bar.#m) {}
}

// @filename: lib.ts
export { Foo as Bar } from "./main";

🙁 Actual behavior

!!! error TS1003: Identifier expected.

!!! error TS2694: Namespace '"tests/cases/conformance/classes/members/privateNames/lib".Bar' has no exported member '(Missing)'.

🙂 Expected behavior

  • no TS1003 Syntax Error
  • TS2694 should report the member name(#m)
@nicolo-ribaudo
Copy link

I wrote this example that hopefully makes it clear why intuition suggests that it should be supported:

// test.ts

export class A {
    static b: 1 = 1;
    static #c: 2 = 2;

    method() {
        type A = typeof A.b;
        type B = typeof import("./test").A.b;

        type C = typeof A.#c;
        type D = typeof import("./test").A.#c;
    }
}

type A and type B are equivalent (both are 1), so I would expect also type C and type D to be equivalent. However, the last one is a syntax error.

(ref #47696)

@jakebailey
Copy link
Member

The original PR that allowed private identifiers in typeof is begin being reverted in #48959; we may not even allow this syntax based on our design meeting discussions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants