I am trying to setup a debugging environment on an 2019 project so I added the following script to my package.json
"dev:debug": "tsc-watch --onFirstSuccess \"node --inspect -r ts-node/register src/app.ts\"",
Running it would give me the following
> node-api-starter@1.0.0 start:dev D:\p\my-project
> tsc-watch --onFirstSuccess "node --inspect -r ts-node/register src/app.ts"
7:18:10 AM - Starting compilation in watch mode...
7:18:27 AM - Found 0 errors. Watching for file changes.
Debugger listening on ws://127.0.0.1:9229/b9a130c4-473d-4b55-a512-50ae9cff15a3
For help, see: https://nodejs.org/en/docs/inspector
D:\p\my-project\node_modules\ts-node\src\index.ts:423
return new TSError(diagnosticText, diagnosticCodes)
^
TSError: ⨯ Unable to compile TypeScript:
src/api/auth/auth.controller.ts:580:29 - error TS2339: Property 'auth' does not exist on type 'Request<ParamsDictionary>'.
580 user.refreshToken = req.auth.refreshToken;
~~~~
src/api/auth/auth.controller.ts:581:23 - error TS2339: Property 'user' does not exist on type 'Request<ParamsDictionary>'.
581 user.userId = req.user.id;
~~~~
src/api/auth/auth.controller.ts:617:82 - error TS2339: Property 'auth' does not exist on type 'Request<ParamsDictionary>'.
617 const user = await userService.getUserInfoByCustomColumn("refreshToken", req.auth.refreshToken);
~~~~
src/api/auth/auth.controller.ts:782:76 - error TS2339: Property 'user' does not exist on type 'Request<ParamsDictionary>'.
782 const user = await userService.getUserInfoByCustomColumn("userId", req.user.id, true);
~~~~
src/api/auth/auth.controller.ts:800:46 - error TS2339: Property 'user' does not exist on type 'Request<ParamsDictionary>'.
800 await userService.updateUserPassword(req.user.id, insertedNewPassword);
~~~~
at createTSError (D:\p\my-project\node_modules\ts-node\src\index.ts:423:12)
at reportTSError (D:\p\my-project\node_modules\ts-node\src\index.ts:427:19)
at getOutput (D:\p\my-project\node_modules\ts-node\src\index.ts:554:36)
at Object.compile (D:\p\my-project\node_modules\ts-node\src\index.ts:760:32)
at Module.m._compile (D:\p\my-project\node_modules\ts-node\src\index.ts:839:43)
at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Object.require.extensions.(anonymous function) [as .ts] (D:\p\my-project\node_modules\ts-node\src\index.ts:842:12)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
Example of one error
auth.controller.ts - Line 577
const refresh = async (req: Request, res: Response, next: NextFunction) => {
try {
const user = new User();
user.refreshToken = req.auth.refreshToken;
...
}
Request
being a part of the Express library
interface Request<P extends core.Params = core.ParamsDictionary> extends core.Request<P> { }
There are 2 files that declare Express
namespace and export Request
interfaces with different varibales (see below)
request.d.ts
declare namespace Express {
export interface Request {
user?: any;
auth?: any;
}
}
declarations.d.ts
declare module 'draftjs-to-html';
declare namespace Express {
export interface Request {
availableCountries: number[];
language: string;
pagination: {
pageSize: number;
pageNumber: number;
};
}
}
So what happens here is that the first compilation using tsc-watch
is done successfully but then some errors in the project pop up.
- Does that mean that
ts-node
tries to recompile ? - If so, why does it fail? does it compile with a different configuration than
tsc-watch
? - Is there a flag that I could use to skip checking these errors