-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Uint8Array.prototype.constructor
is missing/incorrect type, and probably much more
#58796
Comments
This bit from #32452 seems worth quoting:
|
#32452 is about only accessing the static methods on the constructor and specifically excluding creating another instance of it which is my use case. Since constructor doesn't have the correct typings on classes, I can't use typescript to validate generic types being passed in based on their constructor's signature without asking for the constructor type to be explicitly provided. |
Yeah, that requires |
I did play with their playground links and the problem really is that you can't override the constructor signature. Which in my opinion is a flaw in the language to accurately depict the state of the program. |
Concretely, it's possible and common to write code like class Animal {
constructor(name: string) {}
}
class Dog extends Animal {
constructor(name: string, master: Person) {
super(name);
}
}
/* ... */
const a: Animal = new Dog("Fido", bob); which becomes a type error if |
The above example probably deserves one more line of code class Animal {
constructor(name: string) {}
}
class Dog extends Animal {
constructor(name: string, master: Person) {
super(name);
console.log(master.name);
}
}
/* ... */
const a: Animal = new Dog("Fido", bob);
const b = new a.constructor("Hello"); This call will crash, so the program should have an error, but there's no obvious place to put the error -- |
I see what you mean, that is unfortunate :( |
⚙ Compilation target
esnext
⚙ Library
esnext
Missing / Incorrect Definition
The
Uint8Array.prototype.constructor
is missing. It doesn't display it in intelisense, but also doesn't complain when you completely type it out. When typed out it has the incorrect type ofFunction
instead ofUint8ArrayConstructor
.Since
Uint8Array.prototype.BYTES_PER_ELEMENT
exists, it makes sense for the constructor property to as well. I imagine many types are like this, and not justUint8Array
.Sample Code
Documentation Link
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array#instance_properties
The text was updated successfully, but these errors were encountered: