为了账号安全,请及时绑定邮箱和手机立即绑定

用于默认导出的Typescript界面

用于默认导出的Typescript界面

狐的传说 2021-05-05 13:11:39
对于这样的配置文件,我有一个非常基本的文件夹结构:/config  /button  /colors  /index代码如下:colors.tsexport 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的新手,在网上找不到任何可以清楚说明我做错了什么的教程或示例。
查看完整描述

2 回答

?
潇湘沐

TA贡献1816条经验 获得超6个赞

有两个问题:由于大小写错误,您没有正确导入接口:


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,它可以自动导入正确的依赖项。


查看完整回答
反对 回复 2021-05-13
  • 2 回答
  • 0 关注
  • 120 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信