I'm trying to figure out how to make the following code work.
File: foo.ts
const Foo = () => {
const api = {
address: (): string => {
return '';
}
};
return api;
};
export default Foo;
File: bar.ts
import Foo from './foo';
const Bar = () => {
let api = {
name: (): void => {
const add = api.address();
}
};
Object.assign(api, Foo());
or
api = { ...api, ...Foo() };
return api;
};
export default Bar;
In my tsconfig.json I have "target": "es6" set. When I use Object.assign(), api.address() gives an error:
Property 'address' does not exist on type '{ name(): void; }'.
I've researched this and the recommendation is to use the spread operator. I've tried
api = { ...api, ...Foo() };
which I'm not 100% sure is correct. But I get the same error as above.
When I mouse over api in bar.ts it shows that only name exists
let api: { name(): void; }
Any advice on what I'm doing incorrectly in my code?