Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Svelte +Vite: writable store in Typescript, cannot import Writable<T> interface

In a Svelte project scaffolded using Vite I try to write a Svelte store in Typescript; having troubles with importing Writable<T> interface like below:

import { Writable, writable, derived } from 'svelte/store';

This results in the following error in a browser console:

Uncaught SyntaxError: The requested module '/node_modules/.vite/svelte_store.js?v=16f52463' does not provide an export named 'Writable'.

Is there any way to import Writable<T> interface in such a setup?

like image 362
Tomasz Plonka Avatar asked Dec 23 '22 15:12

Tomasz Plonka


1 Answers

Use import type { Writable } from 'svelte/store';.

Update: From TypeScript 4.5 onwards you should be able to do all imports in one line. So instead of

import type { Writable } from 'svelte/store';
import { writable, derived } from 'svelte/store';

you can do

import { type Writable, writable, derived } from 'svelte/store';
like image 52
paolostyle Avatar answered Apr 09 '23 16:04

paolostyle