serverless-plugin-typescript icon indicating copy to clipboard operation
serverless-plugin-typescript copied to clipboard

Plugin does not recognize custom typings

Open slnz00 opened this issue 6 years ago • 5 comments

Issue

There are some packages that don't have types, so I created an index.d.ts file then I declared them there. It works fine when the source is compiled locally but when I'm trying to run any serverless command, it stucks with the following error: Could not find a declaration file for module ... implicitly has an 'any' type. Try npm install ... if it exists or add a new declaration (.d.ts) file containing declare module ...;

TS Config

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "lib": [
      "es2016",
      "dom"
    ],
    "outDir": ".build",
    "rootDir": "./",
    "removeComments": true,
    "preserveConstEnums": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": false,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "pretty": true,
    "inlineSourceMap": true,
    "inlineSources": true
  },
  "exclude": [
    "node_modules",
    "src/types"
  ],
  "typeRoots": [
    "node_modules/@types",
    "src/types"
  ]
}

slnz00 avatar Apr 24 '19 18:04 slnz00

@slnz00 were you been able to fix this? I'm running into the same issue.

andreyvital avatar May 18 '19 01:05 andreyvital

Oh nevermind! I just fixed my issue following this comment: https://github.com/prisma/serverless-plugin-typescript/issues/92#issuecomment-400984161

andreyvital avatar May 18 '19 01:05 andreyvital

@andreyvital Does this issue need more attention or can I close this in favour of #92?

JackCuthbert avatar Jul 19 '19 00:07 JackCuthbert

same to you

myfreax avatar Jun 05 '21 01:06 myfreax

I resolved this with typeRoots. The typeRoots all paths are relative to the tsconfig.json. My tsconfig.json is below

{
  "compilerOptions": {
    "typeRoots": ["./src/typings/", "./node_modules/@types/"],
    "module": "commonjs",
    .....
  }
}

project directory struct

project
  -- src/typings/global/index.d.ts
  ....

myfreax avatar Jun 05 '21 04:06 myfreax