Skip to content

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

Closed
@magic-akari

Description

@magic-akari

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions