io-ts icon indicating copy to clipboard operation
io-ts copied to clipboard

Building io-ts codecs creates broken `.d.ts`

Open cyberixae opened this issue 5 years ago • 4 comments

🐛 Bug report

Current Behavior

After compiling with tsc the resulting .d.ts files end up having broken declarations. At least the ... 4 more ... part of the following would seem to be invalid.

t.BrandC<t.IntersectionC<[t.PartialC<{
    amendable: t.BooleanC;
    cost: t.BrandC<t.IntersectionC<[t.PartialC<{
        amount: t.UnionC<...>;
        ... 4 more ...;
        currency: t.UnionC<...>;
    }>, t.TypeC<...>]>, import("../../../core/components/cost").CostBrand>;
    fare: t.BrandC<...>;
}>, t.TypeC<...>]>, import("../../../core/components/terms").AmendmentBrand>;

Expected behavior

The resulting .d.ts files should have full type signatures without abbreviations.

Reproducible example

git clone [email protected]:maasglobal/maas-schemas.git
cd maas-schemas/maas-schemas-ts/
yarn
yarn build
grep -R " more " lib

Suggested solution(s)

I don't understand why exactly this happens. I think small examples work because abbreviations are never used for small code bases. As one possible workaround I am thinking about implementing gen.printC(d) for io-ts-codegen in hopes of producing smaller .d.ts files.

Your environment

I imagine this has never worked but hasn't been previously tested with large code bases.

I used the following versions

"fp-ts": "^2.0.5",
"io-ts": "^2.1.2",
"typescript": "^3.9.2"

Upgrading to the following did not fix the problem

"fp-ts": "^2.8.2",
"io-ts": "^2.2.10",
"typescript": "^4.0.2"

cyberixae avatar Sep 04 '20 09:09 cyberixae

I filed a bug against TypeScript microsoft/TypeScript#40354 However, I closed it for now since this felt more like an io-ts problem.

cyberixae avatar Sep 04 '20 09:09 cyberixae

After compiling with tsc the resulting .d.ts files end up having broken declarations

@cyberixae looks like a tsc bug

gcanti avatar Sep 06 '20 07:09 gcanti

I opened a PR against io-ts-codegen with a draft of a printC function that could hopefully be used to make declaration files smaller gcanti/io-ts-codegen#62

cyberixae avatar Sep 08 '20 11:09 cyberixae

TypeScript 4.1 give "TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed." error instead of producing incorrect output. This is nice since the error is less likely to go unnoticed. However, explicit type annotation support is still needed in io-ts-codegen to work around the size limitation.

cyberixae avatar Sep 16 '20 16:09 cyberixae