Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maybe improve types documentation a bit #7003

Merged
merged 60 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
dab0f1f
throwing some ideas at the wall
Rich-Harris Sep 23, 2022
c49ec21
Merge branch 'master' into better-docs
dummdidumm Oct 20, 2022
1fe38a5
better doc visuals from interface definitions
dummdidumm Oct 20, 2022
74eb49b
Merge branch 'master' into better-docs
dummdidumm Nov 16, 2022
6a0bdae
move types representation
dummdidumm Nov 16, 2022
234b7bc
tweak visuals
dummdidumm Nov 16, 2022
522e3f9
silence type error
dummdidumm Nov 16, 2022
4468864
please?
dummdidumm Nov 16, 2022
047c1bd
why don't I get these errors locally
dummdidumm Nov 16, 2022
b156b47
boxes
dummdidumm Nov 17, 2022
0fdda38
border-radius
dummdidumm Nov 17, 2022
e575326
Merge branch 'master' into better-docs
dummdidumm Nov 23, 2022
289569f
auto-prepend "ignore any", remove jsdoc types hack which wrecks jsdoc…
dummdidumm Nov 23, 2022
aceb7f5
remove this file in case we forget later
Rich-Harris Nov 23, 2022
24c70f6
visually group things more tightly
Rich-Harris Nov 23, 2022
f18fb7e
collapse interface blocks
Rich-Harris Nov 23, 2022
0b49e98
dont run twoslash on ts blocks
Rich-Harris Nov 23, 2022
4640f02
add links, fix some css
Rich-Harris Nov 23, 2022
3fa65b0
minor fixes
Rich-Harris Nov 23, 2022
d84b455
config types
Rich-Harris Nov 23, 2022
49e97b0
remove unused code
Rich-Harris Nov 23, 2022
49b00be
merge
Rich-Harris Nov 23, 2022
0553e19
move type extraction script as a precursor to reducing some of the in…
Rich-Harris Nov 23, 2022
2d92e06
distinguish between ts and dts
Rich-Harris Nov 23, 2022
b21ea45
hopefully fix deploy
Rich-Harris Nov 23, 2022
8c6f571
consistent format
Rich-Harris Nov 23, 2022
577823d
reduce indirection a bit
Rich-Harris Nov 24, 2022
5865ae0
nested properties, albeit with terrible styling at the moment
Rich-Harris Nov 24, 2022
de83396
more docs
dummdidumm Nov 24, 2022
e0ec45e
Merge branch 'better-docs' of https://github.com/sveltejs/kit into be…
dummdidumm Nov 24, 2022
6846f2e
improve styles a tiny bit
Rich-Harris Nov 24, 2022
096b0b5
Merge branch 'better-docs' of github.com:sveltejs/kit into better-docs
Rich-Harris Nov 24, 2022
1c39256
flesh out some stuff
Rich-Harris Nov 24, 2022
f2e4799
more stuff
Rich-Harris Nov 24, 2022
f7dab3b
couple more
Rich-Harris Nov 24, 2022
b2e5d17
move SubmitFunction into @sveltejs/kit types
Rich-Harris Nov 24, 2022
bf701a6
use /// type, so type hints get syntax highlighting
Rich-Harris Nov 24, 2022
f6724ac
add some defaults
Rich-Harris Nov 26, 2022
f2bff6c
merge master
Rich-Harris Nov 27, 2022
c21c88c
more defaults
Rich-Harris Nov 27, 2022
7f3c273
remove unused typedef
Rich-Harris Nov 27, 2022
8af5687
consistency
Rich-Harris Nov 27, 2022
3730ec1
fix code snippet
Rich-Harris Nov 27, 2022
39388aa
small tweaks
Rich-Harris Nov 27, 2022
04de262
small fixes
Rich-Harris Nov 27, 2022
866ae0a
tweaks
Rich-Harris Nov 27, 2022
70f2dd7
rename API reference to just reference
Rich-Harris Nov 27, 2022
27cc46e
okay ts doesnt like that
Rich-Harris Nov 28, 2022
f501b45
missed a spot
Rich-Harris Nov 28, 2022
f54eae6
changeset
Rich-Harris Nov 28, 2022
44ae150
fix link
Rich-Harris Nov 28, 2022
8c578dd
refactor code in the direction of separating out config reference
Rich-Harris Nov 28, 2022
063ca96
remove unused code
Rich-Harris Nov 28, 2022
7aac7a8
systematise some stuff
Rich-Harris Nov 28, 2022
0174f5e
generate config docs
Rich-Harris Nov 28, 2022
15b281c
get site building again
Rich-Harris Nov 28, 2022
51ca4f5
hackiest possible workaround
Rich-Harris Nov 28, 2022
a9e30f4
merge master
Rich-Harris Nov 28, 2022
cf949ca
tweak some css
Rich-Harris Nov 28, 2022
0ed36e1
tweaks
Rich-Harris Nov 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 171 additions & 0 deletions documentation/docs/30-types-presentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
---
title: Types presentation
---

Brainstorming ideas for better presentation of types.

Compare the (WIP) examples below with https://kit.svelte.dev/docs/types#sveltejs-kit-cookies, https://kit.svelte.dev/docs/types#sveltejs-kit-config, https://kit.svelte.dev/docs/types#sveltejs-kit-kitconfig and https://kit.svelte.dev/docs/configuration.

The idea is that we'd generate this automatically from `types/index.d.ts` etc (including `@example` and `@default` tags), and configuration would be documented this way rather than via the hand-written https://kit.svelte.dev/docs/configuration.

### @sveltejs/kit

#### Cookies

An interface for interacting with cookies during a request.

```ts
get(name, opts): string | undefined
```

* `name: string` The name of the cookie
* `opts?: import('cookie').CookieParseOptions` An object containing an optional `decode` function

Gets a cookie that was previously set with `cookies.set`, or from the request headers.

```ts
set(name, value, opts): void;
```

* `name: string` The name of the cookie
* `value: string` The cookie value
* `opts?: import('cookie').CookieSerializeOptions` TODO Cookie options

Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` during the current request.

The `httpOnly` and `secure` options are `true` by default, and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP. The `sameSite` option defaults to `lax`.

By default, the `path` of a cookie is the 'directory' of the current pathname. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app.


```ts
delete(name, opts): void;
```

* `name: string` The name of the cookie
* `value: string` The cookie value
* `opts?: import('cookie').CookieSerializeOptions` TODO Cookie options

Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.


```ts
serialize(name, value, opts): string;
```

* `name: string` the name for the cookie
* `value: string` value to set the cookie to
* `opts?: import('cookie').CookieSerializeOptions` TODO Cookie options

Serialize a cookie name-value pair into a Set-Cookie header string.

The `httpOnly` and `secure` options are `true` by default, and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP. The `sameSite` option defaults to `lax`.

By default, the `path` of a cookie is the current pathname. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app.

#### Config

Your project's configuration, exported from svelte.config.js.

```ts
compilerOptions?: CompileOptions
```

Svelte compiler options.

```ts
extensions?: string[]
```

An array of file extensions that should be treated as Svelte components.

Default value: `['.svelte']`

```ts
kit?: KitConfig
```

SvelteKit-specific configuration.

```ts
package?: {...}
```

* `source?: string` `"src/lib"` Path to the source folder.
* `dir?: string` `"package"` Path to write the package to
* `emitTypes?: boolean` `true` Whether to generate `.d.ts` files
* `exports?: (filepath: string) => boolean` `() => true` Whether to include a file in `pkg.exports`
* `files?: (filepath: string) => boolean` `() => true` Whether to include a file in the package

Configuration for `svelte-package`

```ts
preprocess?: any
```

Preprocessing options.

```ts
[key: string]: any;
```

Any additional options required by other tooling.

#### KitConfig

Your SvelteKit-specific configuration.

```ts
adapter?: Adapter
```

Run when executing `vite build` and determines how the output is converted for different platforms. See [Adapters](/docs/adapters).

Default value: `undefined`

```ts
alias?: Record<string, string>
```

An object containing zero or more aliases used to replace values in `import` statements. These aliases are automatically passed to Vite and TypeScript.

```js
/// file: svelte.config.js
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
alias: {
// this will match a file
'my-file': 'path/to/my-file.js',

// this will match a directory and its contents
// (`my-directory/x` resolves to `path/to/my-directory/x`)
'my-directory': 'path/to/my-directory',

// an alias ending /* will only match
// the contents of a directory, not the directory itself
'my-directory/*': 'path/to/my-directory/*'
}
}
};
```

> The built-in `$lib` alias is controlled by `config.kit.files.lib` as it is used for packaging.

> You will need to run `npm run dev` to have SvelteKit automatically generate the required alias configuration in `jsconfig.json` or `tsconfig.json`.

Default value: `{}`

```ts
appDir?: string
```

Default value: `'_app'`

```ts
csp?: {...}
```

* `mode?: 'hash' | 'nonce' | 'auto'` `'auto'` -
* `directives?: CspDirectives` `TODO`
* `reportOnly?: CspDirectives` `TODO`
2 changes: 1 addition & 1 deletion sites/kit.svelte.dev/src/lib/docs/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ function parse({ body, file, slug, code, codespan }) {
slug
});
} else {
throw new Error(`Unexpected <h${level}> in ${file}`);
// throw new Error(`Unexpected <h${level}> in ${file}`);
}

return `<h${level} id="${slug}">${html}<a href="#${slug}" class="anchor"><span class="visually-hidden">permalink</span></a></h${level}>`;
Expand Down