add typings to `get_store_value` (#5269)

Co-authored-by: Julian Laubstein <contact@julianlaubstein.de>
pull/5472/head
Tan Li Hau 4 years ago committed by GitHub
parent 8056829a91
commit 2c5f1c466e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,6 +3,7 @@
## Unreleased
* Support `<slot slot="...">` ([#2079](https://github.com/sveltejs/svelte/issues/2079))
* Add types to `get` function in `svelte/store` ([#5269](https://github.com/sveltejs/svelte/pull/5269))
* Add `EventSource` to known globals ([#5463](https://github.com/sveltejs/svelte/issues/5463))
* Fix compiler exception with `~`/`+` combinators and `{...spread}` attributes ([#5465](https://github.com/sveltejs/svelte/issues/5465))

@ -1,4 +1,3 @@
import { assign } from '../../runtime/internal/utils';
import Stats from '../Stats';
import parse from '../parse/index';
import render_dom from './render_dom/index';
@ -68,7 +67,7 @@ function validate_options(options: CompileOptions, warnings: Warning[]) {
}
export default function compile(source: string, options: CompileOptions = {}) {
options = assign({ generate: 'dom', dev: false }, options);
options = Object.assign({ generate: 'dom', dev: false }, options);
const stats = new Stats();
const warnings = [];

@ -1,3 +1,5 @@
import { Readable } from "svelte/store";
export function noop() {}
export const identity = x => x;
@ -60,7 +62,7 @@ export function subscribe(store, ...callbacks) {
return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
}
export function get_store_value(store) {
export function get_store_value<T, S extends Readable<T>>(store: S): T {
let value;
subscribe(store, _ => value = _)();
return value;
@ -158,4 +160,4 @@ export const has_prop = (obj, prop) => Object.prototype.hasOwnProperty.call(obj,
export function action_destroyer(action_result) {
return action_result && is_function(action_result.destroy) ? action_result.destroy : noop;
}
}

Loading…
Cancel
Save