'Typescript: Compile Utility Types into module's declaration file

This might just be wishful thinking:

I have a module foo that uses the Parameters<> from a different mod bar, and passes it out of the current mod (foo). So now if some new mod baz requires foo, it has to Also install the @types for the mod that foo is using: bar in order to figure out the Parameters<> Type. This feels like a common situation, and I was hoping there was a way to handle it that didn't involve forcing baz to need all the declarations from bar, like a way that the extracted types compiled into foo's declaration maybe. Greatly appreciate any guidance!

module bar index.ts:

export function doSomething(param: any) { }

module foo index.ts:

import { doSomething } from "bar"
export function DoAnotherThing(param: Parameters<typeof doSomething>[0]) {
    doSomething(param)
}

module baz index.ts

import { doAnotherThing } from "foo"

// if @types/bar isn't also installed:
// Type 'unknown' has no matching index signature for type 'number'
doAnotherThing(123)


Solution 1:[1]

Let the dependency tree just do its work. You don't need any special magic here.

You should just need to add @types/bar in the devDependencies of the foo module. Now npm install foo should install foo, bar and @types/bar, and everything should work just fine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex Wayne