In my Angular app, I'm able to access Angular types by installing the package @types/angular. Then in my TS files, I'm able to do things like timeout: ng.ITimeoutService without having to import anything into my file. I can then run tsc and everything compiles just fine. VSCode also does not complain that it can't find ng.ITimeoutService.
However when I try to emulate this behavior with my own custom types, it doesn't work without me having to explicitly import the module in my file. Here's what I'm doing:
Create file
vendor/@types/custom/index.d.tswith contents:export declare class MyClass {...}In my tsconfig.json, I add this path to typeRoots:
"typeRoots": ["./vendor/@types/custom"]
Now in my app file ./app/view.ts, I try to do this:
public myObject: MyClass
However VSCode, as well as tsc, complain:
Cannot find name 'MyClass'
I've even tried using references:
/// <reference path="../vendor/@types/custom/index.d.ts" />
But this gives the same result.
How do I access a type without importing its file, similar to how I'm able to access types in node_modules/@types without having to import them?