Skip to content

Commit

Permalink
p34
Browse files Browse the repository at this point in the history
Signed-off-by: baizhi958216 <1475289190@qq.com>
  • Loading branch information
baizhi958216 committed Apr 8, 2023
1 parent b055f55 commit e34f7f4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { p30 } from "./courses/p30";
import { p31 } from "./courses/p31";
import { p32 } from "./courses/p32";
import { p33 } from "./courses/p33";
import { p34 } from "./courses/p34";

/* p01();
p02();
Expand Down Expand Up @@ -110,5 +111,6 @@ export class Storage implements StorageCls {
p29();
p30();
p31();
p32(); */
p33();
p32();
p33(); */
p34();
43 changes: 43 additions & 0 deletions src/courses/p34.ts
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 };

0 comments on commit e34f7f4

Please sign in to comment.