用于默认导出的Typescript界面

对于这样的配置文件,我有一个非常基本的文件夹结构:


/config

  /button

  /colors

  /index

代码如下:


colors.ts


export interface Colors {

  [key: string]: string,

}


export default {

  black: '#111',

  grey: '#999',

  green: '#4c8857',

  red: '#bd1414',

  white: '#fff',

};

索引


import colors from './colors';


export default {

  button,

  colors,

};

我收到以下错误:


Could not find a declaration file for module './colors'. '/xxxxx/styles/config/colors.js' implicitly has an 'any' type.

我是Typescript的新手,在网上找不到任何可以清楚说明我做错了什么的教程或示例。


狐的传说
浏览 172回答 2
2回答

潇湘沐

有两个问题:由于大小写错误,您没有正确导入接口:import colors from './colors';export interface Colors {尝试import {Colors} from './colors';但是在这里,您只是导出“颜色”界面,而不是颜色对象。您可能想要的代码如下:export interface Colors {  [key: string]: string,}export const defaultColors: Colors = {  black: '#111',  grey: '#999',  green: '#4c8857',  red: '#bd1414',  white: '#fff',};然后导入import {defaultColors} from './colors'注意:如果您在导入方面遇到困难,强烈建议您使用像Webstorm这样的IDE,它可以自动导入正确的依赖项。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript