0
我有一个接口的特定配置变量。导出打字稿变量及其类型信息
//I declare my interface
interface ServerConfiguration {
development: {
db: {
url: string,
user: string,
password: string,
},
webServer: {
port: number;
rootPath: string;
}
};
}
//I declare a variable that uses that interface
const config: ServerConfiguration = {
development: {
db: {
url: "someUrl",
user: "myuser",
password: "mypassword",
},
webServer: {
port: process.env.PORT || 9001,
rootPath: rootPath,
},
},
};
// I export my variable
export {config};
后,我将其导入并尝试创建旨在消耗该配置
// I import my variable
import config = require("./config");
// I create a function that will consume a variable that complies with that interface
function initializeDatabase(config: ServerConfiguration) {
//do stuff
}
在这里,我得到错误“无法找到名为‘ServerConfiguration’”的功能,有什么不对?
你建我的IDE,解决我的github上的问题,写我的打字稿手动和现在的答案我的stackoverflow问题。 你是某种互联网上帝还是什么?也许我应该打印你的照片并把它放在蜡烛旁边。 反正,谢谢!你太棒了!! –
只是一个爱打字并帮助别人的人。像你这样的人使这一切都值得 – basarat