Generic models error: "No base constructor has the specified number of type arguments. ts(2508)"
See original GitHub issueI’ve stumbled over a TS typing issue related to generic models where I am getting the error
No base constructor has the specified number of type arguments. ts(2508)
on the Model(...) call. I’ve isolated the problem to the following reduced example:
type ValueType = number | string
class Value<T extends DataType> extends Model(<T extends DataType>() => ({
data: prop<T>(),
}))<T> {}
class Container<V extends Value<T>, T extends DataType> extends Model(< // <--- ERROR
V extends Value<T>,
T extends DataType
>() => ({
value: prop<V>(),
}))<V, T> {}
It doesn’t seem to be caused by:
- more than one generic type parameter (because there’s a test with two type parameters that succeeds)
- simple dependence of one type parameter on another one because the following (replacing
Value<T>byRecord<string, T>) works:type DataType = number | string class Container<V extends Record<string, T>, T extends DataType> extends Model(< V extends Record<string, T>, T extends DataType >() => ({ value: prop<V>(), }))<V, T> {}
So it looks like it’s caused by the dependence of one type parameter on another that extends a generic model. This is as far as I’ve been able to narrow it down. I’m just not sure yet how to fix it. Any help is much appreciated. 🙏
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Cannot extend Promise object: No base constructor has the ...
Try this... class MyPromise<T> extends Promise<T> { constructor(executor: (resolve: any, reject: any) => MyPromise<T>) { super((resolve, ...
Read more >Cannot extend generic type with a mixin · Issue #21710 - GitHub
A class that extends Promise. Actual behavior: TS2508: No base constructor has the specified number of type arguments. Playground Link: Here.
Read more >C++ Standard Core Language Active Issues - open-std.org
Section Issue Status
3 intro.defs 783 open
3 intro.defs 2632 open
3.54 defns.signature.templ 2520 review
Read more >TypeScript errors and how to fix them
error TS2345: Argument of type ' number ' is not assignable to parameter of type ' TimerHandler '. Broken Code ❌. 1 2...
Read more >Changelog - Cypress Documentation
Fixed a regression introduced in the Electron browser in Cypress 10.8.0 where the CYPRESS_EVERY_NTH_FRAME environment variable was not being set appropriately ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I looked into it further and found the issue. Should be fixed in 0.64.1
As a side note, if TS were to allow the usage of types in base expressions all of this would be so much easier