Skip to content

Commit 05291d0

Browse files
committed
11
1 parent 7275d58 commit 05291d0

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Diff for: .vitepress/config.mts

+4-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ export default defineConfig({
171171
{
172172
text: '实践',
173173
collapsed: false,
174-
items: [{ text: '1. 索引签名', link: '/typescript/practice/No1' }],
174+
items: [
175+
{ text: '1. 索引签名', link: '/typescript/practice/No1' },
176+
{ text: '2. TS中泛型 Record<string, any>', link: '/typescript/practice/No2' },
177+
],
175178
},
176179
],
177180
'/vitepress/': [

Diff for: typescript/practice/No2.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# TS中泛型 Record<string, any>
2+
3+
### Record
4+
5+
- Record的内部定义,接收两个泛型参数;Record后面的泛型就是对象键和值的类型。
6+
7+
- Record 主要的作用是用来定义对象
8+
9+
```js
10+
const obj: Record<string, string> = {"a": '1'};
11+
12+
// 或者复杂一点的
13+
interface Person {
14+
name: string;
15+
age: number;
16+
}
17+
const obj: Record<string, Person> = {"a": { name: 'dj', age: 12 }};
18+
```

0 commit comments

Comments
 (0)