xoidlabs / xoid

Framework-agnostic state management library designed for simplicity and scalability ⚛
https://xoid.dev
MIT License
158 stars 7 forks source link

Failed to infer Atom of create() upon DTS generation via tsc/tsup #4

Closed thihathit closed 1 year ago

thihathit commented 2 years ago

First of all, thank you for the library with it's simple API, super awesome work!

image

How did this happen?

It happens when the consuming project uses pnpm & tries to generate .d.ts files via either tsup(uses tsc under the hood) or tsc.

Example

import { create } from 'xoid/esm'

const atom = create({ one: true })

const atom2 = create({ two: true })

Workaround

The workaround is to define type, at least once per file where create is used.

import { create, Atom } from 'xoid/esm'

const atom: Atom<{ one: boolean }> = create({ one: true })

const atom2 = create({ two: true })

IMO, this only happens on libraries with some sort of shared module structure, xoid/etc.... So I'm not sure on which one's end, tsc, pnpm or xoid. Another similar issue is with nuxt's sub-modules.

Might also related to this tsc issue: #42873

onurkerimov commented 2 years ago

Hi @thihathit, thank you for the kind words, and thank you for reporting! Does the problem disappear if xoid is imported from 'xoid' and not 'xoid/esm'? In the first major version, I'm planning to change imports such that:

"main": "index.js",
"module": "index.esm.js"

I believe it will fix the same problem for some environments.

thihathit commented 2 years ago

Sadly xoid is also affected

onurkerimov commented 1 year ago

The 1.0.0-beta.0 release addresses this issue. There's only one index.d.ts file and therefore the same problem shouldn't occur anymore, so I'm closing this issue.

thihathit commented 1 year ago

yes, it's working on beta. thank you.