Search code examples
typescriptnestjstsconfigtsconfig.json

Typescript build error after tsconfig changes?


I am working with NestJs and Typescript 4.7.4. I am having an issue when Architecture team decide to update tsconfig like this

compilerOptions: {
   "target": "es2020",
...
}

to

compilerOptions: {
   "target": "es2023",
   "moduleDetection": "force", // add more 
   "isolatedModules": true, // add more
   "useDefineForClassFields": true, // add more
   "allowJs": true, // add more
   "forceConsistentCasingInFileNames": true, // add more
   "skipLibCheck": true // add more
}

Now, all my Decorators like @HttpCode(200) or @Controller(SomeClass.url) build failed with this error

TS1241: Unable to resolve signature of method decorator when called as an expression.

TS1270: Decorator function return type void | TypedPropertyDescriptor<unknown> is not assignable to type void | TypedPropertyDescriptor<(body: SomeClassBodyDto) => Promise<SomeClassResponseDto>>

I have searched for similar errors, but they always lead to some solutions that need to change tsconfig or using some flag when ts build without any explanation why or at least it too short to understand in-depth.

I want to ask what happen, why my decorators complain about these errors and how to resolve it without touch any tsconfig?


Solution

  • based on @sasha-who's answer (though my solution not related at all but her feedback give me some ideas) I have looked for some compatibility-related stuff. It turns out there is a mismatch between Architecture team's package.json and mine. After update typescript version and other nestjs packages too, it works tottaly fine.