Skip to content

Commit 1c5681e

Browse files
maybe improve types documentation a bit (#7003)
* throwing some ideas at the wall * better doc visuals from interface definitions * move types representation * tweak visuals * silence type error * please? * why don't I get these errors locally * boxes * border-radius * auto-prepend "ignore any", remove jsdoc types hack which wrecks jsdoc hover code in editors * remove this file in case we forget later * visually group things more tightly * collapse interface blocks * dont run twoslash on ts blocks * add links, fix some css * minor fixes * config types * remove unused code * move type extraction script as a precursor to reducing some of the indirection, to make it easier to work on nested properties * distinguish between ts and dts * hopefully fix deploy * consistent format * reduce indirection a bit * nested properties, albeit with terrible styling at the moment * more docs * improve styles a tiny bit * flesh out some stuff * more stuff * couple more * move SubmitFunction into @sveltejs/kit types * use /// type, so type hints get syntax highlighting * add some defaults * more defaults * remove unused typedef * consistency * fix code snippet * small tweaks * small fixes * tweaks * rename API reference to just reference * okay ts doesnt like that * missed a spot * changeset * fix link * refactor code in the direction of separating out config reference * remove unused code * systematise some stuff * generate config docs * get site building again * hackiest possible workaround * tweak some css * tweaks Co-authored-by: Simon Holthausen <[email protected]>
1 parent 0165711 commit 1c5681e

40 files changed

+1057
-630
lines changed

.changeset/bright-pianos-flow.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'create-svelte': patch
3+
---
4+
5+
Update app.d.ts files

.changeset/light-toes-rush.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
Add more type documentation

.changeset/young-needles-attack.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
[breaking] move SubmitFunction into @sveltejs/kit

documentation/docs/20-core-concepts/20-load.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export async function load({ fetch, params }) {
243243
244244
### Cookies and headers
245245

246-
A server-only `load` function can get and set [`cookies`](/docs/types#sveltejs-kit-cookies).
246+
A server-only `load` function can get and set [`cookies`](/docs/types#public-types-cookies).
247247

248248
```js
249249
/// file: src/routes/+layout.server.js
@@ -544,7 +544,7 @@ To summarize, a `load` function will re-run in the following situations:
544544
- It references a property of `params` whose value has changed
545545
- It references a property of `url` (such as `url.pathname` or `url.search`) whose value has changed
546546
- It calls `await parent()` and a parent `load` function re-ran
547-
- It declared a dependency on a specific URL via [`fetch`](#making-fetch-requests) or [`depends`](/docs/types#sveltejs-kit-loadevent), and that URL was marked invalid with [`invalidate(url)`](/docs/modules#$app-navigation-invalidate)
547+
- It declared a dependency on a specific URL via [`fetch`](#making-fetch-requests) or [`depends`](/docs/types#public-types-loadevent), and that URL was marked invalid with [`invalidate(url)`](/docs/modules#$app-navigation-invalidate)
548548
- All active `load` functions were forcibly re-run with [`invalidateAll()`](/docs/modules#$app-navigation-invalidateall)
549549

550550
Note that re-running a `load` function will update the `data` prop inside the corresponding `+layout.svelte` or `+page.svelte`; it does _not_ cause the component to be recreated. As a result, internal state is preserved. If this isn't what you want, you can reset whatever you need to reset inside an [`afterNavigate`](/docs/modules#$app-navigation-afternavigate) callback, and/or wrap your component in a [`{#key ...}`](https://svelte.dev/docs#template-syntax-key) block.

documentation/docs/30-advanced/70-packaging.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ When you're creating an app, the contents of `src/routes` is the public-facing s
1010

1111
A component library has the exact same structure as a SvelteKit app, except that `src/lib` is the public-facing bit. `src/routes` might be a documentation or demo site that accompanies the library, or it might just be a sandbox you use during development.
1212

13-
Running the `svelte-package` command from `@sveltejs/package` will take the contents of `src/lib` and generate a `package` directory (which can be [configured](/docs/configuration#package)) containing the following:
13+
Running the `svelte-package` command from `@sveltejs/package` will take the contents of `src/lib` and generate a `package` directory (which can be [configured](/docs/configuration)) containing the following:
1414

15-
- All the files in `src/lib`, unless you [configure](/docs/configuration#package) custom `include`/`exclude` options. Svelte components will be preprocessed, TypeScript files will be transpiled to JavaScript.
16-
- Type definitions (`d.ts` files) which are generated for Svelte, JavaScript and TypeScript files. You need to install `typescript >= 4.0.0` for this. Type definitions are placed next to their implementation, hand-written `d.ts` files are copied over as is. You can [disable generation](/docs/configuration#package), but we strongly recommend against it.
15+
- All the files in `src/lib`, unless you [configure](/docs/configuration) custom `include`/`exclude` options. Svelte components will be preprocessed, TypeScript files will be transpiled to JavaScript.
16+
- Type definitions (`d.ts` files) which are generated for Svelte, JavaScript and TypeScript files. You need to install `typescript >= 4.0.0` for this. Type definitions are placed next to their implementation, hand-written `d.ts` files are copied over as is. You can [disable generation](/docs/configuration), but we strongly recommend against it.
1717
- A `package.json` copied from the project root with all fields except `"scripts"`, `"publishConfig.directory"` and `"publishConfig.linkDirectory"`. The `"dependencies"` field is included, which means you should add packages that you only need for your documentation or demo site to `"devDependencies"`. A `"type": "module"` and an `"exports"` field will be added if it's not defined in the original file.
1818

19-
The `"exports"` field contains the package's entry points. By default, all files in `src/lib` will be treated as an entry point unless they start with (or live in a directory that starts with) an underscore, but you can [configure](/docs/configuration#package) this behaviour. If you have a `src/lib/index.js` or `src/lib/index.svelte` file, it will be treated as the package root.
19+
The `"exports"` field contains the package's entry points. By default, all files in `src/lib` will be treated as an entry point unless they start with (or live in a directory that starts with) an underscore, but you can [configure](/docs/configuration) this behaviour. If you have a `src/lib/index.js` or `src/lib/index.svelte` file, it will be treated as the package root.
2020

2121
For example, if you had a `src/lib/Foo.svelte` component and a `src/lib/index.js` module that re-exported it, a consumer of your library could do either of the following:
2222

@@ -54,7 +54,7 @@ To publish the generated package:
5454
npm publish ./package
5555
```
5656

57-
The `./package` above is referring to the directory name generated, change accordingly if you configure a custom [`package.dir`](/docs/configuration#package).
57+
The `./package` above is referring to the directory name generated, change accordingly if you configure a custom [`package.dir`](/docs/configuration).
5858

5959
### Caveats
6060

documentation/docs/50-api-reference/10-configuration.md

-307
This file was deleted.

documentation/docs/50-api-reference/meta.json

-3
This file was deleted.

0 commit comments

Comments
 (0)