During the initial page load, I am looking to transfer data from a template to a TypeScript file by attaching it to the window
object. I want each page to utilize the same variable name for its specific data (window.data
). An example of this can be seen in the use of window.props.
In my TypeScript entry point files for different pages (e.g. foo.ts
and
bar.ts</code), I declare the data on the <code>window
object as follows:
declare global {
interface Window {
data: {
foo: string;
};
}
}
For another page like bar.ts
, the declaration would look like:
declare global {
interface Window {
data: {
bar: int;
};
}
}
These TypeScript files are declared as separate entry points in webpack. When compiling, an error message is displayed:
TS2717: Subsequent property declarations must have the same type. Property 'data' must be of type '{ bar: string; }', but here has type '{ foo: string; }'.
Is there a way to resolve these errors without using unique names for each object?