#Import enum and type from definitions.d.ts file
4 messages · Page 1 of 1 (latest)
@crisp echo You should just be able to use a regular import (not a type-only import):
import { MyEnum } from './definitions.ts';
import type { FooBar } from './definitions.ts'
You can't use import type with an enum because it's not just a type that can be erased at compile time. It produces actual JavaScript output. Try creating an enum on the TypeScript playground and you can see what the JavaScript output looks like.
You also don't have to use a type-only import, in case you want to import them together:
import { MyEnum, FooBar } from './definitions.ts';
I tried
import { MyEnum } from './definitions.ts';
import type { FooBar } from './definitions.ts'
// also tried this
import { MyEnum, type FooBar } from './definitions.ts';
but I get this error
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
It's like the definitions.ts file goes missing.
I am using Nuxt so I'm not sure if it's an issue with Nuxt
OK, that suggests the server is serving the TypeScript files directly without compiling them first. TypeScript code can't run directly in the browser. I'll check the Nuxt docs for TypeScript...