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

The inferred type of 'LogEntryEventCodec' cannot be named without a reference to '@huckleberryai/core/node_modules/io-ts-types/lib/optionFromNullable'. This is likely not portable. A type annotation is necessary.

Open dragosrotaru opened this issue 5 years ago • 2 comments

🐛 Bug report

Current Behavior

When I extend a Type from an external module, I get the error mentioned in the issue title.

import * as iots from "io-ts";
import { NonEmptyString } from "io-ts-types/lib/NonEmptyString";
import {  EventCodec } from "@huckleberryai/core";

... LogLevelCodec defined ...

export const LogEntryEventCodec = iots.intersection(
  [
    EventCodec,
    iots.type({
      message: NonEmptyString,
      level: LogLevelCodec,
      tags: iots.array(NonEmptyString)
    })
  ],
  LogEntryEventType
);

To fix the error, I have to add the following import:

import "io-ts-types/lib/optionFromNullable"

In my @huckleberryai/core package:

export const EventCodec = iots.type({
  timestamp: TimeStampCodec,
  type: TypeCodec,
  context: TypeCodec,
  origin: TypeCodec,
  id: UUIDCodec,
  corr: UUIDCodec,
  parent: optionFromNullable(UUIDCodec),
  agent: optionFromNullable(UUIDCodec),
});

Expected behavior

I expect that when I write a Codec that uses an io-ts-type, I can export that codec in our internal packages and import it without issues.

Suggested solution(s)

I'm not really sure how you would fix this. Would love for someone to explain to me what is going on

Additional context

I should also mention that

  • I use lerna to symlink my packages during development.
  • fp-ts, io-ts, io-ts-types are installed in every package

Your environment

Software Version(s)
fp-ts ^2.1.0
io-ts ^2.0.1
io-ts-types ^0.5.1
TypeScript ^3.5.3

dragosrotaru avatar Oct 08 '19 22:10 dragosrotaru

@DragosRotaru I am not sure if you still have the issue. I just had a similar one in one project of mine. At the end it was related, as far as I have discovered, to the fact that the dependency io-ts-types (in your use case) is a dependency of your module (@huckleberryai/core). You should move it to a to dev dependency and add it also as a peer dependency. Once you add io-ts-types to your main project (the external module that is using @huckleberryai/core) it should work as expected.

apalumbo avatar Feb 16 '21 21:02 apalumbo

In my experience, the only thing that worked was to add export { OptionFromNullableC } from "io-ts-types"; to every place I had import "io-ts-types/lib/optionFromNullable"

HtH, Dan

dbernar1 avatar May 20 '21 23:05 dbernar1