Search code examples
node.jstypescriptsequelize.jsdefinitelytyped

Is it possible to force typescript to use types from DefinitelyTyped instead of native lib types?


I'm trying to migrate to sequelize v5 which now has built-in typescript types. I'm not exactly happy how said types are written: data-related methods (find/create/update/etc) use "object" as data values type. Types from DefinitelyTyped are written using generics and dont have such drawback.

The problem is now typescript compiler detects built-in types from sequelize and ignores DefinitelyTyped types. Is there a way to change this behaviour?


Solution

  • This question provides a solution:

    In your .tsconfig.json file:

    {
      ...
      "compilerOptions": {
        ...
        "baseUrl": ".",
        "paths": {
           "*": [
             "types/*", // locally defined types
             "node_modules/@types/*" // DefinitelyTyped typings for applicable packages
           ]
        }
      }
      ...
    }
    

    This means the compiler will first look in your local /types folder, and then in node_modules/@types/, before resorting to the lib-defined typings.