我正在尝试导入一个JSON文件,其中的翻译字符串取决于TSX中要在整个组件中使用的语言环境。
import ComponentStrings from "../t9n/t9nComponentStrings.json";在我的TSConfig.json中,为了做到这一点,我打开了以下...
"resolveJsonModule": true,
"esModuleInterop": true,所以我可以直接在Typescript中导入JSON文件。
但是,当我尝试将它用作这样的类型时……
componentStrings: ComponentStrings = null;我得到了这个打字错误...
'ComponentStrings' refers to a value, but is being used as a type here. Did you mean 'typeof ComponentStrings'?如何将JSON文件作为类型导入并在我的Typescript中使用?为了避免为每个单独的JSON转换文件创建类型,或者使用任何类型?
发布于 2021-05-14 03:23:43
我可以使用typeof来解决这个错误...
componentStrings: typeof ComponentStrings = null;但不确定是否有更好的方法,这样我就不用这么做了。
https://stackoverflow.com/questions/67525034
复制相似问题