Skip to content

Commit 96d2199

Browse files
authored
Add docs for JS entrypoints (#907)
1 parent d69430c commit 96d2199

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

frontend/docs/about-slow-types.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,64 @@ allowed.
254254
+ type MyPrivateMember = string;
255255
```
256256

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+
257315
## Simple inference
258316

259317
In a few cases, JSR can infer a type without you needing to specify it

frontend/docs/go.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const slowTypesRedirects = new Map([
5555
],
5656
["unsupported-ts-export-assignment", "#commonjs-features"],
5757
["unsupported-ts-namespace-export", "#global-augmentation"],
58+
["unsupported-javascript-entrypoint", "#javascript-entrypoints"],
5859
]);
5960

6061
export function go(id: string): string | null {

0 commit comments

Comments
 (0)