commenthol/debug-level

typescript declarations?

Closed this issue · 9 comments

dcsan commented

wondering if you'd rebuild this with typescript declarations?

npm i --save-dev @types/debug-level

@dcsan As I see that a lot of modules are moving into ESM only, I am considering to do a rewrite here as well. TS types will be part of it.

dcsan commented

pure ESM i have always found to be a huge pain in typescript projects, so that would be a blocker at least for me.
conversion of anything in process is a huge undertaking. maybe for something completely green field.
but ESM doesn't really add anything over typescript?

one example
ai/nanoid#365

Can you pls. try v3.0.0-0 which contains the desired changes? It comes bundled with types, esm and cjs.

dcsan commented

🙇 I will at some point soon, thanks!

I just installed v3.0.0-0

Unfortunately I get this:

Could not find a declaration file for module 'debug-level'. '/home/gunhaxxor/origoshift/node_modules/.pnpm/debug-level@3.0.0-0/node_modules/debug-level/lib/index.cjs' implicitly has an 'any' type.
  Try `npm i --save-dev @types/debug-level` if it exists or add a new declaration (.d.ts) file containing `declare module 'debug-level';

@Dealerpriest 3.0.0-1 should now export the types. Can you please confirm.

I now get the types when doing

import { Log } from 'debug-level'

But typescript complains in this way:
image

I tried to import using require('debug-level') and also import('debug-level') but noen of those methods seem to give the types.

Perhaps you could use something like tsup to create the package? I've used it for some packages and it seems to always give me typescript packages that can be consumed by both cjs and esm.

@Dealerpriest
I think this is a problem in your local setup.

I suspect that your tsconfig.json contains

  "module": "NodeNext",

but your package.json does not contain a

  "type": "module",

With this I can reproduce the error. If setup correctly, no error message is displayed.

You are correct. Thank you for this! Works great!
🎉✨