sveltetools / svelte-pathfinder

Tiny, state-based, advanced router for SvelteJS.
MIT License
127 stars 12 forks source link

Add types to npm package #5

Closed samal-rasmussen closed 3 years ago

samal-rasmussen commented 3 years ago

My VS Code is complaining that types are not available:

Could not find a declaration file for module 'svelte-pathfinder'. '.../node_modules/.pnpm/svelte-pathfinder@2.1.2_svelte@3.31.0/node_modules/svelte-pathfinder/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/svelte-pathfinder` if it exists or add a new declaration (.d.ts) file containing `declare module 'svelte-pathfinder';`ts(7016)

@types/svelte-pathfinder doesn't exist, but yet the svelte-pathfinder source code is actually in Typescript, so I went ahead and enabled declarations in tsconfig.json, so that types are emitted and can be included in the npm package directly.

The build output changed quite a bit for some reason. All my actual changes are in package.json and tsconfig.json. The rest is just changes caused by running npm run build.

PaulMaly commented 3 years ago

I need some time to review and I'll back with results as soon as possible. Thanks!

samal-rasmussen commented 3 years ago

I tried using this commit in my svelte project that I'm working on, but then I got this error when running it: Uncaught ReferenceError: Cannot access 'pathStore' before initialization

For some reason Rollup had decided to bundle pathStore later in the build output. I saw there was a warning about circular references between index.ts and stores.ts, so I tried pulling out the common code to a new shared.ts file, and that fixed this issue, and it also reverted all the changes to the build output that I mentioned previously. I have pushed this new commit.