dipscope / TypeManager.TS

Transform JSON strings or plain objects into JS class instances.
https://dipscope.com/type-manager/what-issues-it-solves
Apache License 2.0
24 stars 3 forks source link

NUXT Support #16

Closed DellanX closed 11 months ago

DellanX commented 11 months ago

Is your feature request related to a problem? Please describe.

I'm trying to add this library to a NUXT App (so that I can build a native app). The moment I add the @Type() decorator, NUXT throws a VITE compilation error:

[vite-node] [VITE_ERROR] /utils/models/core/user.ts
at /utils/models/core/user.ts] {
  cause: {
    statusMessage: 'Vite Error',
    message: '[vite-node] [VITE_ERROR] /utils/models/core/user.ts',
    stack: '[vite-node] [VITE_ERROR] /utils/models/core/user.ts\n' +
      'at /utils/models/core/user.ts'
  },
  statusCode: 500,
  fatal: false,
  unhandled: false,
  statusMessage: 'Vite Error',
  data: undefined,
  __nuxt_error: true
}

Don't quite know why, and I do have the following in my .tsconfig file

{
  // https://nuxt.com/docs/guide/concepts/typescript
  "extends": "./.nuxt/tsconfig.json",
  // ...
  "compilerOptions": {
    // ...
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "useDefineForClassFields": false
  }
}

Describe the solution you'd like

There will likely need to be a module for adding type-manager into NUXT.

Describe alternatives you've considered

Kindof at a roadblock here. May switch to the non-decorator method for the meantime, but the decorator method is quite pretty.

Additional context

Add any other context or screenshots about the feature request here.

dpimonov commented 11 months ago

Hi DellanX, thanks for using a library and continuously reporting issues. Which version of TypeScript are you using with NUXT? The only reason I see that it might be related to this issue about TypeScript version 5. Library uses interface from core TypeScript and there should not be any issues when used with proper version and options. I don't have experience with NUXT so at least more details about what kind of error it encounters might help.

DellanX commented 11 months ago

Oh man, I uncovered a whole new can of worms (https://github.com/nuxt/nuxt/discussions/16185). NUXT doesn't like experimental decorators and ignores my tsconfig settings to enable it.

Your library is working fantastic, I just need to fight with NUXTs rollup and nitro mechanisms.

PS, thanks for all the great work on these libraries, they are 10/10. While me migrating to the entity system has definitely found a bunch of snags, it's a huge improvement overall! 😊

DellanX commented 11 months ago

Closing this issue, as it is basically a repeat of https://github.com/dipscope/TypeManager.TS/issues/15 If using experimental decorators, then refer to https://github.com/nuxt/nuxt/discussions/16185

I haven't solved the issue for myself yet.

dpimonov commented 11 months ago

Thanks for the feedback! 😊

I hope you will find a solution. As you already mentioned - going with declarative configuration might be an option. It works exactly the same and contains the same number of features. However amount of code is for sure larger as decorators hide all of this setup behind.