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

Use interfaces #1

Closed
benkeil opened this issue Aug 13, 2020 · 5 comments
Closed

Use interfaces #1

benkeil opened this issue Aug 13, 2020 · 5 comments

Comments

@benkeil
Copy link

benkeil commented Aug 13, 2020

I have a file Foo.ts

export default interface Foo {
  name: string;
}

and want to include it into App.svelte

import Foo from './Foo';
const foo: Foo = {
  name: 'foo',
};

and get an error:

[!] Error: 'default' is not exported by src/Foo.ts, imported by src/App.svelte
@codeitlikemiley
Copy link

think this is cause by rollup plugin typescript....

i tried to use parcel
https://github.com/goldcoders/svelte-tsc

it works , @codechips any reason this is not working on your set up?
misconfigured?

i hate compile time of parcel but the no config saves me headache for this stuffs...
sad tradeoff , ill try to test this on svite ...

if that work then i can move out of parcel

@goldcoders
Copy link

@benkeil you should use

export interface Foo {
  name: string;
};

then on your App.svelte

import type {Foo} from './foo'

const foo: Foo = {
  name: 'bar'
}

console.log(foo.name)

The reason behind is the compiler automatically stripped TYPE (Interfaces that is imported) so it throws an error,

on typescript documentation it is sited there that you need to use import type...

@codechips
Copy link
Owner

Exactly. I've read somewhere (don't remember now) that exporting interfaces does not work very well.

Maybe this one? pyoner/svelte-typescript#23

@goldcoders
Copy link

been studying typescript together with rust this lockdown for months, all this static analysis is killing me lol
but its worth investment since the technology is going towards web assembly , wasm , rust, typescript.

I have actually preparing myself for building a hugo site manager with rust , svelte and typescript...
so finding the best Bundler to speed up development is a must..

@codechips can you sugguest your best set up? :)

@codechips
Copy link
Owner

Hmm .. Hugo like in static site generator written in Go? If going down that route parcel is probably the best because it only needs one entry file in your main html file. However, I do not recommend you to use parcel as it produces large and not that optimal production bundles compared to Rollup.

I would probably use pure Vitejs myself here with its Svelte plugin. Vitejs supports HMR, PostCSS, TS and other nice things, plus it uses Rollup for production bundles. Currently it also uses esbuild for Typescript, but see here vitejs/vite#788

As of Rust and WASM, I have no knowledge here except that Vite can import precompiled WASM files.

Snowpack is also an option, but I would personally stay away from it for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants