Skip to content

Commit

Permalink
11
Browse files Browse the repository at this point in the history
  • Loading branch information
squid-Xu committed Aug 20, 2024
1 parent 7275d58 commit 05291d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ export default defineConfig({
{
text: '实践',
collapsed: false,
items: [{ text: '1. 索引签名', link: '/typescript/practice/No1' }],
items: [
{ text: '1. 索引签名', link: '/typescript/practice/No1' },
{ text: '2. TS中泛型 Record<string, any>', link: '/typescript/practice/No2' },
],
},
],
'/vitepress/': [
Expand Down
18 changes: 18 additions & 0 deletions typescript/practice/No2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# TS中泛型 Record<string, any>

### Record

- Record的内部定义,接收两个泛型参数;Record后面的泛型就是对象键和值的类型。

- Record 主要的作用是用来定义对象

```js
const obj: Record<string, string> = {"a": '1'};

// 或者复杂一点的
interface Person {
name: string;
age: number;
}
const obj: Record<string, Person> = {"a": { name: 'dj', age: 12 }};
```

0 comments on commit 05291d0

Please sign in to comment.