2

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?

eko
  • 39,722
  • 10
  • 72
  • 98
  • You could give it a type that includes the base property, specifically (`{ base: number }`) or generally (`{ [key: string]: number }`). Or just `any`, but then you might as well not use TS. – jonrsharpe Jul 08 '17 at 10:26
  • Possible duplicate of [TypeScript any vs Object](https://stackoverflow.com/questions/18961203/typescript-any-vs-object) – eko Jul 08 '17 at 10:28

1 Answers1

6

Solution

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;
Community
  • 1
  • 1
Khalid
  • 332
  • 3
  • 4