3

I'm trying to add a custom types file to my angular project. I created typings.d.ts inside my Angular project (created with the CLI), inside the src folder. Then inside my tsconfig.json I have

"types": [
    "src/typings.d.ts"
]

but regardless of what I've tried, I always get this error. Though from what I've Google over the last hour has been types is for specific files whereas typeRoots are for type directories.

ERROR in ./src/app/profile-mobile/profile-mobile.component.ts

Module not found: Error: Can't resolve 'src/typings' in 'C:\Users\errat\Documents\Projects\chat\src\app\profile-mobile'

also weirdly: Error from chokidar (C:\): Error: EBUSY: resource busy or locked, lstat 'C:\DumpStack.log.tmp'

Though these errors don't happen after adding the types file, it's only after importing the Type in an angular component to use it (I don't even have to be using it).

1
  • AFAIK, you could denote files as well in the typeRoots property: "typeRoots": [ "node_modules/@types", "../src/typings.d.ts" ], but then you need to explicitly include the node_modules/@types. If not, they might be excluded. Commented Jul 31, 2020 at 23:01

1 Answer 1

5

In the documentation of typescript there is

By default all visible ”@types” packages are included in your compilation

so you should not even add your declaration to tsconfig.json, it will work by default as long as you have this declaration under your root

The error, that you got, happens, because you try to import declaration file (*.d.ts) into component, it will not work like that, because declaration files is a separate type of files and you can not import them like usual esnext modules

if you have some interfaces, that you want to use, just create usual *.ts files and import them like usual module with import ... from ...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.