gcanti / io-ts-types

A collection of codecs and combinators for use with io-ts
https://gcanti.github.io/io-ts-types/
MIT License
311 stars 40 forks source link

Type 'IntFromStringC' is not assignable to type 'Mixed' #109

Closed Varkal closed 4 years ago

Varkal commented 4 years ago

🐛 Bug report

Current Behavior

Currently this snippet :

const querySchema = t.partial({
    limit: IntFromString,
    offset: IntFromString,
    lang: t.string,
});

Throw a compiler Error (that can be silenced by cast IntFromString as any)

Type 'IntFromStringC' is not assignable to type 'Mixed'.
  Types of property 'pipe' are incompatible.
    Type '<B, IB, A extends IB, OB extends A>(this: Type<A, string, unknown>, ab: Type<B, OB, IB>, name?: string) => Type<B, string, unknown>' is not assignable to type '<B, IB, A extends IB, OB extends A>(this: Type<A, any, unknown>, ab: Type<B, OB, IB>, name?: string) => Type<B, any, unknown>'.
      The 'this' types of each signature are incompatible.
        Type 'Type<A, any, unknown>' is not assignable to type 'Type<IB, string, unknown>'.
          Types of property 'is' are incompatible.
            Type 'Is<A>' is not assignable to type 'Is<IB>'.
              Type predicate 'u is A' is not assignable to 'u is IB'.
                Type 'A' is not assignable to type 'IB'.
                  'A' is assignable to the constraint of type 'IB', but 'IB' could be instantiated with a different subtype of constraint '{}'.
                    Type 'IB' is not assignable to type 'IB'. Two different types with this name exist, but they are unrelated.
                      'IB' is assignable to the constraint of type 'IB', but 'IB' could be instantiated with a different subtype of constraint '{}'.

15     limit: IntFromString,
       ~~~~~

  node_modules/@marblejs/middleware-io/node_modules/io-ts/lib/index.d.ts:456:5
    456     [key: string]: Mixed;
            ~~~~~~~~~~~~~~~~~~~~~
    The expected type comes from this index signature.
src/effects/query.effects.ts:16:5 - error TS2322: Type 'IntFromStringC' is not assignable to type 'Mixed'.

16     offset: IntFromString,
       ~~~~~~

  node_modules/@marblejs/middleware-io/node_modules/io-ts/lib/index.d.ts:456:5
    456     [key: string]: Mixed;
            ~~~~~~~~~~~~~~~~~~~~~
    The expected type comes from this index signature.

Expected behavior

Should compile :-)

Your environment

Software Version(s)
fp-ts 2.1.0
io-ts 2.0.1
io-ts-types 0.5.1
TypeScript 3.6.3
giogonzo commented 4 years ago

I can't reproduce the issue with the same lib versions. Could you also:

Varkal commented 4 years ago

Right ! @marblejs/middleware-io doens't use the last version of io-ts. Sorry :-(