Description
🔎 Search Terms
"incompatible augmentation", "augmentation across modules"
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about module augmentation across packages
(Using codesandbox since Playground doesn't let you emulate multiple files/packages.)
⏯ Playground Link
https://codesandbox.io/s/flamboyant-feistel-m2rs99?file=/src/index.ts
💻 Code
// package-a
declare global {
interface ReadableStream<R = any> extends AsyncIterable<R> {
}
}
export declare const readableStreamToDataURL: (value: Uint8Array | ReadableStream<Uint8Array>) => Promise<string>;
// package-b
import { readableStreamToDataURL } from "package-b";
declare function writeFileToSomewhere(path: string, contents: string): void;
interface ReadableStream<R = any> extends AsyncIterable<R> {}
export const writeFile = async (path: string, value: string | Uint8Array | ReadableStream<Uint8Array>) => {
if (typeof value !== "string") {
value = await readableStreamToDataURL(value);
}
return writeFileToSomewhere(path, value);
};
🙁 Actual behavior
Augmenting a global type (ReadableStream
) in one package doesn't seem to import the type in the other package.
Making the same augmentation in both packages breaks type checking if each package uses its augmented type as a function parameter.
[0] src/bridge.ts:45:43 - error TS2345: Argument of type 'Uint8Array | ReadableStream<Uint8Array>' is not assignable to parameter of type 'Uint8Array | ReadableStream<Uint8Array>'.
[0] Type 'ReadableStream<Uint8Array>' is not assignable to type 'Uint8Array | ReadableStream<Uint8Array>'.
[0] Type 'ReadableStream<Uint8Array>' is missing the following properties from type 'ReadableStream<Uint8Array>': locked, cancel, getReader, pipeThrough, and 2 more.
[0]
[0] 45 value = await readableStreamToDataURL(value);
[0] ~~~~~
Additionally, the error message is unhelpful. TypeScript is treating the types independently, but gives them both the same name. ReadableStream (defined in 'package-a') is missing the following properties from type ReadableStream (defined in 'package-b')
would be a better error message.
🙂 Expected behavior
Global augmentations in an imported package affect local types. I shouldn't have to augment the type in two places.
However, since the augmentations are identical, I expect the type checking to pass even if they are defined independently.
Additional information about the issue
No response