We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Consider a generic class, such as:
class Foo<T> { constructor(public value: T) {} }
This works:
const foo = new Foo<string>("abc");
But this does not, currently:
const foo = new Foo("abc");
It fails with:
ERROR TS2558: Expected 1 type arguments, but got 0. : 5 │ const foo = new Foo("abc"); │ ~~~~~~~~~~~~~~ └─ in assembly/index.ts(5,13)
I would expect type inference to work on constructors, the same as it presently does for functions. Consider that this does work:
function createFoo<T>(value: T): Foo<T> { return new Foo(value); } const foo = createFoo("abc");
And type inference on static methods works too:
class Foo<T> { constructor(public value: T) {} static create<T>(value: T): Foo<T> { return new Foo(value); } } const foo = Foo.create("abc");
The text was updated successfully, but these errors were encountered:
@CountBleck do you have time to take a look at this? It should be simple--I tried, but im not too familiar with the codebase
Sorry, something went wrong.
Hm, if type inference exists for generic functions, it should be relatively simple to implement for constructors (famous last words).
I may dig into this myself a bit. 🤞
Successfully merging a pull request may close this issue.
Feature suggestion
Consider a generic class, such as:
This works:
But this does not, currently:
It fails with:
I would expect type inference to work on constructors, the same as it presently does for functions. Consider that this does work:
And type inference on static methods works too:
The text was updated successfully, but these errors were encountered: