forked from baizhi958216/xiaoman-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: baizhi958216 <1475289190@qq.com>
- Loading branch information
1 parent
b055f55
commit e34f7f4
Showing
2 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const p34 = () => { | ||
type Person = { | ||
name: string; | ||
age: number; | ||
text: string; | ||
}; | ||
|
||
// Readonly: 传进来的类型全部转成readonly | ||
type Read<T> = { | ||
readonly [P in keyof T]: T[P]; | ||
}; | ||
|
||
type man = Read<Person>; | ||
type man1 = Readonly<Person>; | ||
|
||
// PropertyKey: string | number | symbol | ||
type Rec<K extends PropertyKey, T> = { | ||
[P in K]: T; | ||
}; | ||
|
||
type key = "A" | "B" | "C"; | ||
|
||
type man2 = Rec<key, Person>; | ||
|
||
let obj: man2 = { | ||
A: { | ||
name: "小满", | ||
age: 22, | ||
text: "真男人", | ||
}, | ||
B: { | ||
name: "小满", | ||
age: 22, | ||
text: "真男人", | ||
}, | ||
C: { | ||
name: "小满", | ||
age: 22, | ||
text: "真男人", | ||
}, | ||
}; | ||
}; | ||
export { p34 }; |