`
sillycat
  • 浏览: 2551942 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

TypeScript and Dictionary Index

 
阅读更多
TypeScript and Dictionary Index

I define a Interface, then I define a dictionary variables and want to look up the dictionary based on the key.

interface GroupSettingsMethod { (parameters: any) : Promise<string> | void };
const groupSettingsMethods = {
    '/meeting/create': { 'method': changeGroupMeetingCount },
    '/meeting/update': { 'method': getGroupMeetingCount }
};

..snip…
const methodImpl: GroupSettingsMethod = groupSettingsMethods[uriSuffix.toLowerCase()].method || null;
…snip…

It should lookup the different interface based not he uriSuffix. But in my VS code, it shows up
[ts] Element implicitly has an ‘any’ type because  type ….. has no index signature

I checked some articles here
https://basarat.gitbooks.io/typescript/docs/types/index-signatures.html
https://dev.to/kingdaro/indexing-objects-in-typescript-1cgi

Finally, I solve that by change the dictionary definition to
const groupSettingsMethods:{ [index:string] : any } = {
    '/meeting/create': { 'method': changeGroupMeetingCount },
    '/meeting/update': { 'method': getGroupMeetingCount }
};


References:
https://basarat.gitbooks.io/typescript/docs/types/index-signatures.html
https://dev.to/kingdaro/indexing-objects-in-typescript-1cgi
分享到:
评论

相关推荐

    Building Web Components with TypeScript and Angular 4

    Building Web Components with TypeScript and Angular 4 by Matthew Scarpino English | 10 Jun. 2017 | ASIN: B071K4HWMT | 603 Pages | AZW3 | 2.11 MB Angular is Google's foremost framework for developing ...

    Full-Stack React, TypeScript, and Node

    详细介绍用EC6+构建Apps,使用React开发SPA应用,用create-react-app安装项目、Redux、React Router、TypeScript, Node用Express和GraphQL开发WEB服务等内容。

    Building Web Components with TypeScript and Angular 4 无水印pdf

    Building Web Components with TypeScript and Angular 4 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自...

    build web components with typescript and angular

    本文将介绍如何使用TypeScript和Angular框架构建Web组件。在展开具体知识点之前,我们首先要了解一下TypeScript和Angular的基本概念以及Web组件的相关历史。 1. JavaScript的发展历史:TypeScript是JavaScript的一...

    ORM for TypeScript and JavaScr.zip

    ORM for TypeScript and JavaScr

    Building Web Components with TypeScript and Angular 4 epub

    Building Web Components with TypeScript and Angular 4 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    Advanced TypeScript Programming Projects

    Advanced TypeScript Programming Projects: Build 9 different apps with TypeScript 3 and JavaScript frameworks such as Angular, React, and Vue Gain in-depth knowledge of TypeScript and the latest ...

    Introducing Regular Expressions JavaScript and TypeScript epub

    Introducing Regular Expressions JavaScript and TypeScript 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    Pro TypeScript, 2nd Edition

    Explore the features of this innovative open source language in depth, from working with the type system through object-orientation to understanding the runtime and the TypeScript compiler. This fully...

    TypeScript手册(TypeScript Handbook) 重写新版 PDF版

    2021年3月,TypeScript发布了自己的最新版本手册。该手册是学习 TypeScript 语言及其常用用法的主要资源。官方人员指出,新手册在 TypeScript 团队中已经是一个运行多年的项目,包含了大大小小的数百个贡献。 这项...

    typescript 教程.pdf

    根据提供的文件内容,下面我将详细总结关于TypeScript的知识点。 首先,TypeScript是一种由Microsoft开发的编程语言,它在JavaScript的基础上扩展了类型系统,提供了更多的结构化特性和ES6的支持。由于它能够编译成...

    Typescript类型脚本课件.pptx

    Typescript类型脚本课件 Typescript是一种静态类型检查的JavaScript超集语言,由Microsoft开发,代码开源于GitHub上。Typescript的主要特点是提供了类型系统和对JS新标准的支持(ES6/7/8)。 Typescript可以帮助...

    TypeScript快速上手教程

    TypeScript是一种由微软开发的开源编程语言,它在JavaScript的基础上添加了静态类型系统和其他特性。TypeScript的主要开发者是Anders Hejlsberg,他是著名的编程语言设计大师,曾参与过Turbo Pascal、Delphi、C#等...

    TypeScript

    1)解压之后目录是 typescript_plugin 2)把它整个 typescript_plugin文件拷贝到您安装到Eclipse或者是MyEclipse的一个叫dropins文件夹.然后重载Eclipse/MyEclipse 3)重启Eclipse之后会Window--&gt;&gt;Preferences出现...

    TypeScript教程

    ### TypeScript 数据类型详解 #### 基础数据类型 在 TypeScript 中,基础数据类型是构建更复杂类型的基础。这些类型包括但不限于布尔值、数字、字符串等。 ##### 布尔值(boolean) 布尔值用于表示逻辑实体,在 ...

    Mastering.TypeScript.2nd.epub

    Gain an insight into core and advanced TypeScript language features including inheritance, generics, asynchronous programming techniques, promises, decorators and more Integrate your existing ...

    Mastering TypeScript

    Build enterprise-ready, industrial strength web applications using TypeScript and leading JavaScript frameworks About This Book Focus on test-driven development to help build quality applications ...

    Mastering TypeScript [eBook]

    Build enterprise-ready, industrial strength web applications using TypeScript and leading JavaScript frameworks

    TypeScript Design Patterns(PACKT,2016)

    Use and utilize design patterns while developing a TypeScript application or during JavaScript application development Reference to SOLID principles and what their benefits do to your projects Apply ...

Global site tag (gtag.js) - Google Analytics