首页 > 其他分享 >[Typescript] Show the error close to where it's causes

[Typescript] Show the error close to where it's causes

时间:2024-01-23 21:23:23浏览次数:27  
标签:Typescript const Show component createRoutes error routes path routingConfig

Example code:

const routingConfig = {
  routes: [
    {
      path: "home",
      component: "HomeComponent",
    },
    {
      path: "about",
      component: 12,
    },
    {
      path: "contact",
      component: "ContactComponent",
    },
  ],
};

const createRoutes = (config: {
  routes: {
    path: string;
    component: string;
  }[];
}) => {};

createRoutes(routingConfig);

 

The error message is kind of hard to read. The key problem is The 'number' is not assignable to type 'string', so how to make error message show close to where it's cause?

 

Solution 1: Inline the object:

createRoutes({
  routes: [
    {
      path: "home",
      component: "HomeComponent",
    },
    {
      path: "about",
      component: 12,
    },
    {
      path: "contact",
      component: "ContactComponent",
    },
  ],
});

 

Solution 2: Extra a type

type RoutingConfig = {
  routes: {
    path: string;
    component: string;
  }[];
}

const routingConfig: RoutingConfig = {
  routes: [
    {
      path: "home",
      component: "HomeComponent",
    },
    {
      path: "about",
      component: 12,
    },
    {
      path: "contact",
      component: "ContactComponent",
    },
  ],
};

const createRoutes = (config: RoutingConfig) => {};

createRoutes(routingConfig);

 

Solution 3: satisfies

const routingConfig = {
  routes: [
    {
      path: "home",
      component: "HomeComponent",
    },
    {
      path: "about",
      component: 12,
    },
    {
      path: "contact",
      component: "ContactComponent",
    },
  ],
} satisfies RoutingConfig;

标签:Typescript,const,Show,component,createRoutes,error,routes,path,routingConfig
From: https://www.cnblogs.com/Answer1215/p/17983440

相关文章

  • ERROR:Only one ConfirmCallback is supported by each RabbitTemplate] with root cau
     错误:OnlyoneConfirmCallbackissupportedbyeachRabbitTemplate]withrootcause 原因:因为Spring的Bean默认都是单例;而RabbitTemplate对象同样支持一个回调。 解决:使用@Scope("prototype")可通知Spring将被注解的Bean变为多例。代码: //改Ra......
  • 详解avcodec_encode_video2 AVERROR(EAGAIN)
    详解avcodec_encode_video2AVERROR(EAGAIN)在视频编码过程中,可能会遇到错误码AVERROR(EAGAIN)。本篇技术博客将详细解释avcodec_encode_video2函数中的AVERROR(EAGAIN)错误码的含义,并讨论可能的原因和解决方案。什么是avcodec_encode_video2?avcodec_encode_video2是FFmpeg(一个流行......
  • EasyCVR启动失败报错“Local Machine Check Error”的解决方法
    有用户反馈EasyCVR智能边缘网关启动失败,导致服务无法使用,今天我们来分析一下问题的排查与解决方法。1)查看报错日志,如下:2)报错为“LocalMachineCheckError!本地机器检查错误!”,检查配置文件是否因为hardware_version字段影响了服务启动;3)将该字段参数进行注释,然后再次启动EasyCVR查看......
  • inode爆满error is not recoverable exiting now
      查看    ......
  • Uncaught (in promise) ChunkLoadError: Loading chunk commons.xxxxxxxxx failed
    报错信息如下:Uncaught(inpromise)ChunkLoadError:Loadingchunkcommons.pages_index.pages_teacher_indexfailed. (error:http://localhost:3000/_nuxt/commons.pages_index.pages_teacher_index.js)发生情景:打开多标签时,Nuxt程序崩溃:我有一个vue、nuxt应用程序......
  • error 'vpxservicesMoServiceDirectory'
    error'vpxservicesMoServiceDirectory'][ServiceDirectory]Instanceentrymissingservices:65bf45a事故说明 :当时由于venter环境的win2008磁盘爆满 ,后期发现vcenterclient无法登录 ,过后发现VMwareVirtualCenterServerService为停止状态 ,手动重启失败 ,经......
  • TypeScript 实用技巧(下)
    第六部分:杂项原文:exploringjs.com/tackling-ts/pt_miscellaneous.html译者:飞龙协议:CCBY-NC-SA4.0下一步:23 使用类型进行计算的概述二十三、类型计算概述原文:exploringjs.com/tackling-ts/ch_computing-with-types-overview.html译者:飞龙协议:CCBY-NC-SA4.023.......
  • TypeScript 实用技巧(上)
    第一部分:起步原文:exploringjs.com/tackling-ts/pt_preliminaries.html译者:飞龙协议:CCBY-NC-SA4.0接下来:1 关于本书一、关于这本书原文:exploringjs.com/tackling-ts/ch_about-book.html译者:飞龙协议:CCBY-NC-SA4.01.1 这本书的主页在哪里?1.2 这本书包括什......
  • TypeScript 实用技巧(中)
    十四、向类型添加特殊值原文:exploringjs.com/tackling-ts/ch_special-values.html译者:飞龙协议:CCBY-NC-SA4.014.1 在带内添加特殊值14.1.1 向类型添加null或undefined14.1.2 向类型添加符号14.2 在带外添加特殊值14.2.1 辨别式联合14.2.2 其......
  • error Error: certificate has expired
    报错内容%yarninstallyarninstallv1.22.21infoNolockfilefound.(node:11844)[DEP0040]DeprecationWarning:The`punycode`moduleisdeprecated.Pleaseuseauserlandalternativeinstead.(Use`node--trace-deprecation...`toshowwherethewarningw......