Here is a simple example to illustrate the problem:
// library.d.ts
import type { Bar } from './bar.d.ts';
export interface Foo {
bar?: string | Bar | boolean;
// and many other properties
}
// bar.d.ts
export interface Bar {
baz?: number
// and many other properties
}
My goal is to extract the Bar
type from the Foo['bar']
union, without having to import Bar
separately. How can I achieve this, considering that bar.d.ts
cannot be imported by external consumers of the library?
I attempted to use Extract<Foo['bar'], Bar>
, but it did not work as it still required me to import Bar
, which is not what I wanted.