Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

接口-可索引的类型 #344

Open
luckyriko opened this issue Mar 30, 2023 · 1 comment
Open

接口-可索引的类型 #344

luckyriko opened this issue Mar 30, 2023 · 1 comment

Comments

@luckyriko
Copy link

image
我是TS初学者 这一块看不懂 有可以正常运行的示例吗

@zhongsp
Copy link
Owner

zhongsp commented May 11, 2023

@luckyriko

interface NumberOrStringDict {
  [index: string]: number | string;
  length: number; // ok, length is a number
  name: string; // ok, name is a string
}

这个是一种正确的用法。

如果把 [index: string]: number | string; 写成 [index: string]: number;[index: string]: string; 都不可以。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants