This repository has been archived by the owner on Feb 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
type unknow - error not checked #25
Labels
Comments
Not sure what's the issue here, could you please provide a minimal runnable example reproducing the problem?
|
Dont need to run it, just check it with flow /* @flow */
type getTotalsP = {| from: Date, to: Date, accountId: string |};
async function getTotals({ from, to, accountId }: getTotalsP) {
return 10000;
}
import * as t from 'flow-io/src/index.js';
const TotalReq = t.$exact({
accountId: t.string,
from: t.instanceOf(Array),
to: t.instanceOf(Date),
});
// using type_at_pos here you get type unknown
// but using https://github.com/andreypopp/validated in similar case you get the right type
const params2 = t.fromValidation(({}: any), TotalReq);
// here the schema type does not match return type (should be error)
// {| from: Date, to: Date, accountId: string |} != {| from: Array, to: Date, accountId: string |}
const params: getTotalsP = t.fromValidation(({}: any), TotalReq);
getTotals(params); Anyway, nice project 👍 I will use it at work when the issue is solved. |
Seems a bug of // @flow
import * as t from 'flow-io';
// type-at-pos says correctly ArrayType<Array<string>>
const A = t.array(t.string)
// type-at-pos says (unknown)
const TotalReq = t.object({
accountId: t.string,
from: t.instanceOf(Array),
to: t.instanceOf(Date),
});
// but...
const x = t.fromValidation({}, TotalReq);
// `flow check` correctly shows an error: property `a`. Property not found in object type
x.a
// `flow check` correctly shows no errors
;(x.accountId: string)
;(x.from: Date)
Relevant #11 Btw bugs like these make flow-io hardly usable, that's why I switched to TypeScript https://github.com/gcanti/io-ts |
unrelated: today, which is better, typescript or flow? i knew that typescript were less intelligent (maybe things changed) |
Hi, i got a workaround https://github.com/freddi301/flow-validator |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: