On file 'A' I have this:
export const settings: object = {
base: 1
}
Now on file 'B' I import it and extract the base value:
import * as mySettings from '../settings';
baseValue: object=mySettings.settings.base;
This is returning an error:
property: base does not exist on type: object.
How can I fix this?
On file 'A' I have this:
export const settings: object = {
base: 1
}
Now on file 'B' I import it and extract the base value:
import * as mySettings from '../settings';
baseValue: object=mySettings.settings.base;
This is returning an error:
property: base does not exist on type: object.
How can I fix this?
Share Improve this question edited Jul 8, 2017 at 10:28 eko 40.7k11 gold badges78 silver badges101 bronze badges asked Jul 8, 2017 at 10:21 user8159753user8159753 2-
You could give it a type that includes the base property, specifically (
{ base: number }
) or generally ({ [key: string]: number }
). Or justany
, but then you might as well not use TS. – jonrsharpe Commented Jul 8, 2017 at 10:26 - Possible duplicate of TypeScript any vs Object – eko Commented Jul 8, 2017 at 10:28
1 Answer
Reset to default 6Solution
Remove the type in your code, in this case the word "object"
Results
Creating the Settings File
Create a file with following code, let's save with the name settings
export const settings = {
base: 1
};
Importing the file
Now, import the file with the path '../settings'
, I created a alias mySettings
import * as mySettings from '../settings';
baseValue: number = mySettings.settings.base;