Search code examples
node.jstypescripttypescript-typingsnodemon

NodeJs and Typescript: development mode does not recognize custom types


The error is that when I run with Nodemon the server in development mode sends me the following error due to my custom types:

Property 'returnTo' does not exist on type 'Session & Partial'.

Error: Property 'returnTo' does not exist on type 'Session & Partial

This file is named express-session-types.d.ts and has the following code:

express-session-types.d.ts file

My tsconfig.json is as follows:

tsconfig.json

My package.json scripts: My package.json scripts


Solution

  • The solution I came up with was to force import the types into my server.ts file or project startup file as follows:

    import * as sessionTypes from './types/express-session-types';
    

    Where express-session-types is my module file with extension .d.ts where the property is declared.