Skip to content

Instantiation Expressions from generic class static member #53247

Closed
@JasonKleban

Description

@JasonKleban

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)

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions