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

Instantiation Expressions from generic class static member #53247

Closed
JasonKleban opened this issue Mar 14, 2023 · 1 comment · Fixed by #53441
Closed

Instantiation Expressions from generic class static member #53247

JasonKleban opened this issue Mar 14, 2023 · 1 comment · Fixed by #53441
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@JasonKleban
Copy link

Bug Report

🔎 Search Terms

  • "Only refers to a type, but is being used as a namespace here" TS202
  • "Cannot find name" TS2304
  • "Instantiation Expressions"

🕗 Version & Regression Information

I tried this in Nightly 5.1.0-dev.20230313, 4.7.4, 4.8.4, and 4.9.5 - the versions that support Instantiation Expressions on the playground but it does not complain. This does not cause my build to fail - only the Language Server complains locally.

  • This is the behavior in every version I tried

⏯ Playground Link

NOT exhibited in playground: Playground link with relevant code

But the same code in VSCode latest with nightly typescript:

image

And I hope I'm showing that the right version of tsserver is being used (it would be nice if the TSServer startup announced its version for confirmation).

💻 Code

class Foo<T extends Object, C extends {}> {
    private constructor(value : T, context: C){ }

    static readonly makeFoo = <C extends {}>(context : C) => 
        <T extends Object>(value : T) => 
            new Foo<T, C>(value, context);
}

const x = Foo.makeFoo<{}>;  // Cannot find name 'Foo'.ts(2304)
                            // 'Foo' only refers to a type, but 
                            // is being used as a namespace here.ts(2702)

x({}); // 👍 `const x: <{}>(context: {}) => <T>(value: T) => Foo<T, {}>`

Strangely, the language server is still able to give the right types for that and future related code.

🙁 Actual behavior

Non-blocking errors TS202 TS2304 on the Instantiation Expressions involving a generic static method.

🙂 Expected behavior

Should be OK or have a fully blocking error (hopefully with enough information to fix)

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this and removed Help Wanted You can do this labels Mar 14, 2023
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.1.0 milestone Mar 14, 2023
@RyanCavanaugh
Copy link
Member

This is just a bug. There shouldn't be an error in the LS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants