io-ts: Broken build with typescript@2.9.0-rc
Here’s the error
export type mixed = object | number | string | boolean | symbol | undefined | null
export type Is<A> = (m: mixed) => m is A // <= new error
/*
A type predicate's type must be assignable to its parameter's type.
Type 'A' is not assignable to type 'mixed'.
Type 'A' is not assignable to type 'object'.
*/
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
export type mixed = {} | undefined | null
?
EDIT: best bet so far is
export type mixed = { [key: string]: any } | object | number | string | boolean | symbol | undefined | null
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 15 (7 by maintainers)
Commits related to this issue
- Lock typescript version at 2.8.4. See https://github.com/gcanti/io-ts/issues/174 — committed to freight-hub/TypedEnv by artfwo 6 years ago
- Fix broken build with typescript@2.9.1, closes #174 — committed to gcanti/io-ts by gcanti 6 years ago
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
mixed
. However looks good enough forio-ts
, let me explain what I mean. I chose{ [key: string]: any }
because it plays well witht.Dictionary
. In fact, in “idiomatic”io-ts
you would definefoo
asFinally, as @sledorze pointed out, in the TypeScript repo there’s some work related to
unknown
(https://github.com/Microsoft/TypeScript/pull/24439) andany
(https://github.com/Microsoft/TypeScript/pull/24423) so maybe we should just wait the next release and then try to changemixed
to@gcanti works also for me with
typescript@2.9.1
.My guess was wrong,
unknown
is coming in TypeScript 3, see Announcing TypeScript 2.9.1@sledorze so in the meanwhile I would go for
WDYT?
No errors at compilation time. Looks good to me 👍
FYI just tried
typescript@3.0.0-dev.20180531
(which already containsunknown
) andtype mixed = unknown
works like a charm