-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Flow not checking new C
when C
is type Class<...>
#2930
Comments
Maybe something like this declare class RecordClass<T> {
constructor(o: $Shape<T>): this;
}
declare function Record<T: Object>(o: T): Class<RecordClass<T>>;
const ABRecord = Record({a: 1, b: 2})
// or const ABRecord: Class<RecordClass<{a: number, b: number}>> = Record({a: 1, b: 2})
const a = new ABRecord({}) |
Hm. How come your example typechecks correctly and my example doesn't? :) Oh, that's because I have |
Once I edit the examples to use declare class Foo {
constructor(a: number): void;
};
function construct(FooClass: Class<Foo>) {
const w = new FooClass('this is a string');
} Bam, it throws an error like it should. I will close this. |
Oh, the problem was because Record cannot extend T. So I cannot write
So I tried to "hack" it by using types
but then the In the end I will probably end up writing some typed wrapper around Records. |
I have this code and I would expect it to throw error; but it doesn't.
Similarly, this doesn't check errors
I found no other way to say 'this variable is a class, you can call new() on it, only with the expected parameters, and it makes a new object of that type'. Maybe
Class
is not correct, but then what is;$Type
and friends doesn't work either.I am needing this, because I want to write at least somehow correct immutable-js Record typedefs;
var ABRecord = Record({a: 1, b: 2})
doesn't create a new record, but a new class, on which you can callnew ABRecord({})
. I want to capture that.The text was updated successfully, but these errors were encountered: