I am generating my Typescript types through my Laravel project with Spatie Typescript Transformers. I am then importing the Types & Enums into my Nuxt project through a separate package via node modules
It looks like this
// node_modules/@laravel-types/index.d.ts
declare namespace App.Enums {
export enum ExampleEnum {
"ExampleValue" = 0,
}
}
declare namespace App.Models {
export type ExampleType = {
id: number;
title: string;
enum: App.Enums.ExampleEnum;
};
}
I have no problem using the types of App.Models throughout my Nuxt project. But when using the App.Enums I am getting the error Uncaught (in promise) ReferenceError: App is not defined
I have tried to change my nuxt.config.ts compiler options adding declaration & declarationMap and include the package
// nuxt.config.ts
typescript: {
shim: false,
strict: true,
typeCheck: true,
tsConfig: {
compilerOptions: {
declarationMap: true,
declaration: true,
},
include: [
'../node_modules/@larave-types/types/index.d.ts',
],
},
},
But that doesnt work. Seemingly the enums shouldnt be declared in a d.ts file. But since thats an external package I have no influence over the content inside it. So I need to find a way to deal with it as it is
I have also tried to add the enums as local ts file which are referencing the type of the enums from the package like
//./types/enums.ts
export const ExampleEnum: typeof App.Enums.ExampleEnum = {
ExampleValue: 0,
}
this works locally but then the gitlab.ci pipeline is throwing me an error
types/enums.ts(1,42): error TS2708: Cannot use namespace 'App' as a value.