Add types to individual functions

pull/8452/head
Puru Vijay 3 years ago
parent a42a769b51
commit 218849c3ec

@ -6,6 +6,8 @@ The `svelte` package exposes [lifecycle functions](/tutorial/onmount) and the [c
## `onMount` ## `onMount`
> EXPORT_SNIPPET: svelte#onMount
```js ```js
onMount(callback: () => void) onMount(callback: () => void)
``` ```
@ -48,6 +50,8 @@ If a function is returned from `onMount`, it will be called when the component i
## `beforeUpdate` ## `beforeUpdate`
> EXPORT_SNIPPET: svelte#beforeUpdate
```js ```js
beforeUpdate(callback: () => void) beforeUpdate(callback: () => void)
``` ```
@ -68,6 +72,8 @@ Schedules a callback to run immediately before the component is updated after an
## `afterUpdate` ## `afterUpdate`
> EXPORT_SNIPPET: svelte#afterUpdate
```js ```js
afterUpdate(callback: () => void) afterUpdate(callback: () => void)
``` ```
@ -88,6 +94,8 @@ Schedules a callback to run immediately after the component has been updated.
## `onDestroy` ## `onDestroy`
> EXPORT_SNIPPET: svelte#onDestroy
```js ```js
onDestroy(callback: () => void) onDestroy(callback: () => void)
``` ```
@ -108,6 +116,8 @@ Out of `onMount`, `beforeUpdate`, `afterUpdate` and `onDestroy`, this is the onl
## `tick` ## `tick`
> EXPORT_SNIPPET: svelte#tick
```js ```js
promise = tick(); promise = tick();
``` ```
@ -128,6 +138,8 @@ Returns a promise that resolves once any pending state changes have been applied
## `setContext` ## `setContext`
> EXPORT_SNIPPET: svelte#setContext
<!-- TODO: Better typing information --> <!-- TODO: Better typing information -->
```js ```js
@ -150,6 +162,8 @@ Like lifecycle functions, this must be called during component initialisation.
## `getContext` ## `getContext`
> EXPORT_SNIPPET: svelte#getContext
```js ```js
context: any = getContext(key: any) context: any = getContext(key: any)
``` ```
@ -166,6 +180,8 @@ Retrieves the context that belongs to the closest parent component with the spec
## `hasContext` ## `hasContext`
> EXPORT_SNIPPET: svelte#hasContext
```js ```js
hasContext = hasContext(key: any) hasContext = hasContext(key: any)
``` ```
@ -184,6 +200,8 @@ Checks whether a given `key` has been set in the context of a parent component.
## `getAllContexts` ## `getAllContexts`
> EXPORT_SNIPPET: svelte#getAllContexts
```js ```js
contexts: Map<any, any> = getAllContexts() contexts: Map<any, any> = getAllContexts()
``` ```
@ -200,6 +218,8 @@ Retrieves the whole context map that belongs to the closest parent component. Mu
## `createEventDispatcher` ## `createEventDispatcher`
> EXPORT_SNIPPET: svelte#createEventDispatcher
```js ```js
dispatch: ((name: string, detail?: any, options?: DispatchOptions) => boolean) = createEventDispatcher(); dispatch: ((name: string, detail?: any, options?: DispatchOptions) => boolean) = createEventDispatcher();
``` ```

@ -64,6 +64,16 @@ export function replace_placeholders(content) {
}) })
.join('')}`; .join('')}`;
}) })
.replace(/> EXPORT_SNIPPET: (.+?)#(.+)?$/gm, (_, name, id) => {
const module = modules.find((module) => module.name === name);
if (!module) throw new Error(`Could not find module ${name}`);
if (id) {
const exported = module.exports.find((t) => t.name === id);
return `<div class="ts-block">${fence(exported.snippet)}</div>`;
}
})
.replace('> MODULES', () => { .replace('> MODULES', () => {
return modules return modules
.map((module) => { .map((module) => {

Loading…
Cancel
Save