admin管理员组文章数量:1326461
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;
本文标签: javascriptAngular export import object (getting object data)Stack Overflow
版权声明:本文标题:javascript - Angular export import object (getting object data) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742212338a2433941.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论