-
Notifications
You must be signed in to change notification settings - Fork 12.8k
When class declared and returned in the function, .d.ts declaration does not meet the expectations #50492
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
Comments
Your expected behavior has errors; there is no type named declare const Foo: {
new (): {
name: string;
extend(): Foo; // error!
};
};
declare const foo_instance: {
name: string;
extend(): Foo; // error!
};
declare const foo1: {
name: string;
extend(): Foo; // error!
}; Presumably you'd actually want to see something like #463 or #44045 where the currently anonymous type you're calling interface Foo {
name: string;
extend(): Foo;
}
const Foo = class {
name: string = 'shulandmimi';
extend(): Foo {
return new Foo();
}
};
const foo_instance = new Foo();
const foo1 = foo_instance.extend(); |
thanks for your reply, the solution you proposed did work for me, but I still have some questions
It doesn't seem to conform to #463 circular reference to itself When a class is declared and returned in a function, there are two cases // 1
function createFoo() {
class Foo {
extend(): Foo {
return new Foo();
}
}
return Foo;
}
// 2
function createFoo() {
return class Foo {
extend(): Foo {
return new Foo();
}
}
} In the playground, 1 will throw a reference to a private type error, while 2 will generate a type from typeof Foo and run without error But in the second case, during the generation of .d.ts, Foo will be replaced by typeof Foo, and Foo will be discarded, causing the extend method to return any Should this be the case instead of the current solution
|
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
🔎 Search Terms
When class declared and returned in the function, .d.ts declaration does not meet the expectations
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
🙂 Expected behavior
The text was updated successfully, but these errors were encountered: