You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you use the JSR package @korkje/memz through npm, the Typescript type definitions for it are broken and unusable. The package works completely as expected when instead used through JSR directly with Deno.
Here's an example of the issue, using the first example from its readme which fails to typecheck when the library is used through npm:
$ npm init --init-type module -y
$ npm i typescript
$ npx tsc --init --module node16
$ npx jsr add @korkje/[email protected]
$ npx tsc --noEmitexample.ts:3:13 - error TS2554: Expected 2 arguments, but got 1.3 const add = memoize((a: number, b: number) => a + b); ~~~~~~~ node_modules/@korkje/memz/_dist/lib/memoize.d.ts:6:80 6 */ export declare const memoize: <P extends unknown[], R>(fn: (...p: P) => R, _dts_1: never) => any; ~~~~~~~~~~~~~ An argument for '_dts_1' was not provided.Found 1 error in example.ts:3
Here's the original code from the package, memoize.ts:
/** * Wrap any function with a cache. Default keyFn is `JSON.stringify`. * * @param fn - The function to memoize. * @param options - Options (keyFn, initial cache). */exportconstmemoize=<Pextendsunknown[],R>(fn: (...p: P)=>R,{ keyFn =JSON.stringify, cache ={}}: {keyFn?: (params: P)=>string|number|symbol;cache?: Record<string|number|symbol,R>;}={},)=>(...p: P): R=>cache[keyFn(p)]??=fn(...p);exportdefaultmemoize;
Here's the resulting typescript type definition file in the npm package, node_modules/@korkje/memz/_dist/lib/memoize.d.ts:
/** * Wrap any function with a cache. Default keyFn is `JSON.stringify`. * * @param fn - The function to memoize. * @param options - Options (keyFn, initial cache). */exportdeclareconstmemoize: <Pextendsunknown[],R>(fn: (...p: P)=>R,_dts_1: never)=>any;exportdefaultmemoize;//# sourceMappingURL=memoize.d.ts.map
The second parameter of the memoize function should be optional (because a default value is provided in the original source file) and it should have a type like { keyFn?: ...; cache?: ...; }. Instead, the definition file has the parameter as non-optional and of the type never.
It seems like JSR's type definition generation might fail to handle function parameters where the parameter has a default value, the parameter is destructured, and the destructured values themselves have default values. (I would love to know how to run JSR's npm package generation locally so I could easily test the limits of what's handled without having to resort to publishing a package, and also that would be handy knowledge for npm-link use-cases too.)
The text was updated successfully, but these errors were encountered:
When you use the JSR package @korkje/memz through npm, the Typescript type definitions for it are broken and unusable. The package works completely as expected when instead used through JSR directly with Deno.
Here's an example of the issue, using the first example from its readme which fails to typecheck when the library is used through npm:
example.ts:
Here's the original code from the package, memoize.ts:
Here's the resulting typescript type definition file in the npm package, node_modules/@korkje/memz/_dist/lib/memoize.d.ts:
The second parameter of the memoize function should be optional (because a default value is provided in the original source file) and it should have a type like
{ keyFn?: ...; cache?: ...; }
. Instead, the definition file has the parameter as non-optional and of the typenever
.It seems like JSR's type definition generation might fail to handle function parameters where the parameter has a default value, the parameter is destructured, and the destructured values themselves have default values. (I would love to know how to run JSR's npm package generation locally so I could easily test the limits of what's handled without having to resort to publishing a package, and also that would be handy knowledge for npm-link use-cases too.)
The text was updated successfully, but these errors were encountered: