Resolving TypeScript Errors After Configuring Node.js Subpath Imports in Shared Package

I am trying to create a shared package in which I will put a bunch of effect utils that I am re-using accross similar projects (such as schemas).

A bit of context before explaining my issue:
In my shared package I am using Node.js subpath imports, such as (but not exactly like):
"imports": {
  "#*": "./*",
}

Everything was working fine, however I realized that, on top of my ./dist folder, I was also publishing my non compiled dir. So I modified my configuration so that I only publish my ./dist folder.

This caused an issue since the subpath imports was now misconfigured. Until then, when importing a schema like:
import { SomeSchema } from "@somepackage/someSchema" was actually pointing to the initial .ts and not the compiled ones.

I fixed that. But now that this is fixed I have typescript flagging error on every schema using my shared packaged schemas.

For example :
// type => brand<Union<[typeof DateFromSelf, typeof SDate]>, "SafeDateTime">
export const SafeDateTime = Union(DateFromSelf, SDate)
  .annotations({
    identifier: "SafeDateTime",
    title: "SafeDateTime",
    description: "A date either coming from a string or a Date object",
  })
  .pipe(brand("SafeDateTime"));

const Foo = Struct({
  occurredAt: SafeDateTime,
});

Is working fine.

However when I try to use it from my shared package
import { SafeDateTime } from "<package>/common/dateTime";

const Foo = Struct({
  occurredAt: SafeDateTime,
});


I get this error:
TS2322: Type

brand<Union<[typeof DateFromSelf, typeof Date$]>, "SafeDateTime">

is not assignable to type

Schema.All | PropertySignature.All<PropertyKey>

Property [TypeId] is missing in type
brand<Union<[typeof DateFromSelf, typeof Date$]>, "SafeDateTime">

but required in type Schema<never, never, unknown>


Which brings me to my question:
1. Wtf am I doing wrong aha ?
2. When trying to share schemas (or anything else) through shared published packages, isn't it the way to proceed ?
Was this page helpful?