Hi,
I am maintaining a package @y/impl-package-types, which contains the type definitions for package @x/impl-package (note that they live under different scopes. I am not sure if this has any relevance, I just added it for completeness sake). I can not move @y/impl-package-types to Definitely Typed, nor can I add and ship the types with @x/impl-package.
Assume @y/impl-package-types consists of just one index.d.ts on root level with the following contents:
// index.d.ts
declare module '@x/impl-package' {
export function fn (x: number, y: number): number
}
which is the full description of @x/impl-package's API. I want to make these types available when the user does:
import * as impl from '@x/impl-package'
One way of doing this seems to be adding either compilerOptions.types: ["@y/impl-package-types"] or compilerOptions.typeRoots: ["./@y"] to the consumer's tsconfig.json. In both cases, the types can be properly resolved. But I am confused by the description for both options in the manual. Based on the manual, specifying these options should override their default behaviour.
For example, the docs for typeRoots says:
If typeRoots is specified, only packages under typeRoots will be included.
https://www.typescriptlang.org/tsconfig/#typeRoots
So I would assume types living in ./node_modules/@types/… (the default value) to no longer be found. But I can not verify this. A consumer project with the following files resolves the types for both my impl project and express perfectly fine: