Microsoft/TypeScript

Please Allow Mixins to function properly with new-able types

Open

#53,737 建立於 2023年4月11日

在 GitHub 查看
 (1 留言) (0 反應) (0 負責人)TypeScript (6,726 fork)batch import
BugDomain: JSDocHelp Wanted

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

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

貢獻者指南