How do I type this code properly (without using ES6 classes)
function Cat(name) {
this.name = name;
}
const staticProps = {
legs: 4
};
const prototype = {
meow: function() { return "meow" + this.name }
};
Object.assign(Cat, staticProps, {prototype: prototype});
// Cat.legs
// => 4
// const kitty = new Cat('kitty');
// kitty.meow();
// => "meowkitty"
I am currently getting the error
property `legs`. Property not found in statics of function
oops, think i found it.
https://flowtype.org/docs/quick-reference.html#callable-objects
will re-open if i'm still having trouble
Still having trouble. how do I do this?
That link is now broken with the doc update :(
In your example, you basically have a class. You can just use the ES6 class syntax for it. If for some reason, you can't use ES6 syntax, you can use flow comment to work around the problem.
https://flow.org/try/#0GYVwdgxgLglg9mABAYQIZQBRlQWwKYCUiA3gFCKJQAWMAzgHTb6IC8iTeA3KQL6mkQEtKImHoYEAAoAnOAAdarEuUQAbPAHNaALkQAWXtwFCRc2VDhQAnnLxKyFfHADuu0JFgIMRYoml4oEGkkACInZxDEAGpKGgYORD4eIwB5ACMAKzxoelRaWhgNMAw0KAAaUShxKVkFCuIzS0sbPF1Gi2tbHgIjAHoAKm1tUgATbNVUf0QICfzEAH1S5QoOXWFpGDANbgoxWAg1TR12EBw0vGkdxHDvNagNre4+ft7+QTBhFHRkWeOfvNoAB5FugAHxKEroXSoMBWHpAA
I see now, that making classes with ES6 is not the best experience.
https://flow.org/en/docs/types/functions/#toc-callable-objects
Example:
type OutputInterceptorType = {|
<T>(routine: () => Promise<T> | T): Promise<T>,
output: ''
|};
@goodmind This issue can be closed, as far as I can tell.
Original example actually works as is
https://flow.org/try/#0GYVwdgxgLglg9mABAYQIZQBRlQWwKYCUiA3gFCKJQAWMAzgHTb6IC8iTeA3KQL6mkQEtKImHoYEAAoAnOAAdarEuUQAbPAHNaALkQAWXtwFCRc2VDhQAnnLxKyFfHADuu0JFgIMRYohUVpPCgQaSQAIidnMMQAakoaBg4-Cj4eIwB5ACMAKzxoelRaWhgNMAwVNCgAGmTRKHEpWQUalWIzS0sbPF12i2tbPgIjSvp1LVIAegmKFgA+fWMwYUQAaxgoayUwPGcUdAwAcjWNqwOh0mPrekjvbimZ+Yi8F0urMKA
I tried all the versions and didn't found where it didn't work
Most helpful comment
I see now, that making classes with ES6 is not the best experience.