简体   繁体   English

TypeScript:在 Typescript 项目中导入模块?

[英]TypeScript: Importing a module in a Typescript project?

I have some static data I am trying create a lookup table for so I have an object in a TS file:我有一些静态数据正在尝试为其创建查找表,因此我在 TS 文件中有一个对象:

newTSFile.ts新的TSFile.ts

export declare module FontList { 
   export DEFAULT_DATA: {
       'james': {
           'age': '23'
        },
        'jack': {
           'age': '22'
        }
   }
}

then in my main TS file, I am importing as然后在我的主 TS 文件中,我导入为

import { FontList } from './newTSFile';

// 
console.log("font list: ", FontList)

however, it still can't find the file when compiling with the error: Error [ERR_MODULE_NOT_FOUND]: Cannot find module .../FontList .但是,在编译时仍然找不到该文件,出现错误: Error [ERR_MODULE_NOT_FOUND]: Cannot find module .../FontList Not sure what I am doing wrong here in regards to importing不确定我在导入方面做错了什么

Try this:-尝试这个:-

newTSFile.ts新的TSFile.ts

export const FontList: { 
       'james': {
           'age': '23'
        },
        'jack': {
           'age': '22'
        }
   }

main TS file主 TS 文件

import { FontList } from './newTSFile';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM