Reputation: 3473
I'm currently trying to create a small npm package library with some utilities for Jasmine testing. The code is in my GitHub https://github.com/DrMueller/MLAH.Testing and contains currently only 2 functions and a type. Unfortunately, I'm not 100% keen on how exactly the magic of the import of the d.ts files work: According to the official documentation:
By default all visible “@types” packages are included in your compilation. Packages in node_modules/@types of any enclosing folder are considered visible; specifically, that means packages within ./node_modules/@types/
Therefore, creating a type like
export type SpyOf<T> = {
[Method in keyof T]: jasmine.Spy;
};
I would guess, that when I remove the typeRoots, the jasmine typings are found, but yet I still get
error TS2503: Cannot find namespace 'jasmine'.
Also taking other properties like include or types into account, according to the documentation, they always delimit the found typings, therefore not specifying them should take all the types in node_modules/@types into account.
The only solution working so far is adding it manually in each file via
/// <reference path="../../node_modules/@types/jasmine/index.d.ts" />
This works for the compilation, but since the created npm package is not in the same relative folder as the code, it throws there an exception.
Am I missing something, or is jasmine some sort of special kind of module?
Upvotes: 1
Views: 1138
Reputation: 30919
I was afraid that solving this would require Angular-specific knowledge that I don't have, but no: I see that angular.json
references src/tsconfig.app.json
and I can reproduce the problem by running tsc -p src/tsconfig.app.json
.
Delete the "types": []
line from src/tsconfig.app.json
. That line is shutting off the automatic loading of all visible @types
packages.
Upvotes: 3