Microsoft/TypeScript

Please Allow Mixins to function properly with new-able types

Open

#53,737 opened on Apr 11, 2023

View on GitHub
 (1 comment) (0 reactions) (0 assignees)TypeScript (6,726 forks)batch import
BugDomain: JSDocHelp Wanted

Repository metrics

Stars
 (48,455 stars)
PR merge metrics
 (Avg merge 6d 17h) (9 merged PRs in 30d)

Description

Bug Report

If we declare a new-able type, that is a mixin with the generic parameter it uses, the whole type is not processed. For example, doing this, won't work

// In types.d.ts
namespace test.ts.bug{
    var MyType: {
        new <T>(): T & {
            additional: "somevalue"
        };
    }
}
// Then, in VS code, we make use of the type as such
/** @extends {test.ts.bug.MyType<{tsc: "cool"|"sweet"}>} */
class SomeClass extends Object{
}
const myVar = new SomeClass()

Suppose you try to use myVar, you won't see the any of the properties corrected listed, and auto-completed.

However, if you declared it like this

// In types.d.ts
namespace test.ts.working{
    var MyType: {
        new <T>():  {
            additional: "somevalue";
            main: T
        };
    }
}

And obviously, did the following in js

// Then, in VS code, we make use of the type as such
/** @extends {test.ts.working.MyType<{tsc: "cool"|"sweet"}>} */
class SomeClass extends Object{
}
const myVar = new SomeClass()

then with const myVar = new SomeClass(), the properties additional, and main.tsc are auto-completed very well.

🔎 Search Terms

mixins new-able newable types

🕗 Version & Regression Information

Same version with vs code

⏯ Playground Link

Playground link with relevant code

🙁 Actual behavior

const myVar = new SomeClass() doesn't auto-complete in VS code

🙂 Expected behavior

const myVar = new SomeClass() is supposed to have the tsc, and additional set to true

Contributor guide