-
Notifications
You must be signed in to change notification settings - Fork 327
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
Broken build with typescript@2.9.0-rc #174
Comments
Why don't you add an upper-bound constraint? (As also mentioned in the linked blog post) export type Is<A extends mixed> = (m: mixed) => m is A The quest for the perfect definition of |
@dippi because that would mean to add an upper-bound constraint everywhere. It would be awkward and, in practice, a breaking change. I'd rather prefer to find a good definition for |
I see, I'm aware of that issue and I agree with your concerns. function foo(m: mixed) {
if (m !== null && typeof m === "object" && "bar" in m) {
const bar = m["bar"] // bar has type any
bar.baz // and the compiler won't complain here
}
} Following my gut I like better the following definition, that needs the upper-bound constraint, but it's less awkward / dangerous to check and access. export type mixed = { [key: string]: mixed } | number | string | boolean | symbol | undefined | null; (note: I'm aware of recursive types limitations and the use of interfaces as a workaround, however I just tried it and, to my surprise, iff the type is exported it seems to work fine) However I honestly cannot fully picture how much awkward it would become and I must admit I don't even use this library, I was just searching for a good definition of |
Unknown type is currently under consideration in typescript |
Well, then thank you for taking the time to chime in, more opinions/suggestions are always helpful.
You are right, my candidate is not a perfect fit for a general purpose definition of function foo(m: t.mixed) {
if (t.Dictionary.is(m) && 'bar' in m) {
const bar = m['bar'] // bar has type mixed
bar.baz // and the compiler DOES complain here
}
} Finally, as @sledorze pointed out, in the TypeScript repo there's some work related to type mixed = unknown |
FYI just tried |
@gcanti what do you think about the proper release / schedule (make it available in 'next' ?) |
@sledorze my plan would be
(*) you can try it now editing |
No errors at compilation time. |
My guess was wrong, @sledorze so in the meanwhile I would go for export type mixed = { [key: string]: any } | object | number | string | boolean | symbol | undefined | null WDYT? |
@gcanti I need to test it! |
@gcanti not compilation error on the code base using your latest proposal. |
My project uses io-ts. With that updated definition for |
@gcanti works also for me with |
Thanks @sledorze @spacejack @mlegenhausen, I'm going to release a patch |
Here's the error
Related: section "Unconstrained type parameters are no longer assignable to object in strictNullChecks" in https://blogs.msdn.microsoft.com/typescript/2018/05/16/announcing-typescript-2-9-rc/
What's the better fix? Changing
mixed
to?
EDIT: best bet so far is
The text was updated successfully, but these errors were encountered: