@@ -254,6 +254,64 @@ allowed.
254
254
+ type MyPrivateMember = string;
255
255
```
256
256
257
+ ## JavaScript entrypoints
258
+
259
+ If a package has a JavaScript entrypoint, JSR will not be able to create type
260
+ definitions for the package. JSR only generates type definitions for TypeScript,
261
+ and not for JavaScript. Using JavaScript entrypoints is not a fatal error: JSR
262
+ will not be able to generate type definitions for the package, and will not show
263
+ documentation for the package - but the package will still be usable.
264
+
265
+ There are two ways to fix this:
266
+
267
+ 1 . Convert the JavaScript entrypoint to TypeScript. This involves renaming the
268
+ file from ` .js ` to ` .ts ` and adding types.
269
+ 2 . Reference a ` .d.ts ` type declaration file from the JavaScript entrypoint, so
270
+ that JSR can use the type declaration file to generate types. This is useful
271
+ if you cannot convert the JavaScript entrypoint to TypeScript, or if the code
272
+ is generated.
273
+
274
+ To reference a ` .d.ts ` type declaration file from a JavaScript entrypoint, there
275
+ are two options:
276
+
277
+ 1 . In the file itself, add a ` /* @ts-self-types="./path/to/types.d.ts" */ `
278
+ directive at the top of the file. This instructs JSR to use the types from
279
+ the specified file, rather than using the file itself.
280
+ 2 . Wherever the file is imported (e.g. in an import statement), add a
281
+ ` /* @ts-types="./path/to/types.d.ts" */ ` directive directly above the import
282
+ statement. This instructs JSR to use the types from the specified file,
283
+ rather than using the file itself when generating types or documentation.
284
+
285
+ ``` js
286
+ // index.js
287
+ /* @ts-self-types="./index.d.ts" */
288
+ export function foo () {
289
+ return " foo" ;
290
+ }
291
+ ```
292
+
293
+ ``` ts
294
+ // index.d.ts
295
+
296
+ export function foo(): string ;
297
+ ```
298
+
299
+ OR
300
+
301
+ ``` js
302
+ // foo.js
303
+ /* @ts-types="./bar.d.ts" */
304
+ import { foo } from " ./bar.js" ;
305
+
306
+ // bar.js
307
+ export function foo () {
308
+ return " foo" ;
309
+ }
310
+
311
+ // bar.d.ts
312
+ export function foo (): string;
313
+ ```
314
+
257
315
## Simple inference
258
316
259
317
In a few cases, JSR can infer a type without you needing to specify it
0 commit comments