Created
December 30, 2022 16:45
-
-
Save reyronald/2bfcd52fab7ab9d2737a3f16fb040562 to your computer and use it in GitHub Desktop.
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
type ValidateShape<T, Shape> = | |
T extends Shape ? | |
Exclude<keyof T, keyof Shape> extends never ? | |
T : never : never; | |
type Exact<A, B> = | |
A extends B ? | |
B extends A ? A | |
: never | |
: never; | |
function Test<T>(_args: ValidateShape<T, { test: string }>) { | |
// | |
} | |
// goood | |
Test({ test: "haha" }); | |
const o1= { test: "haha" } | |
Test(o1); | |
const o2= { test: "haha" } as const | |
Test(o2); | |
const o3 = Object.freeze({ test: "haha" }) | |
Test(o3); | |
/// error | |
Test({ test: "haha", other: "asdf" }); | |
const oe1= { test: "haha", other: "asdf } | |
Test(oe1); | |
const oe2 = { test: "haha", other: "asdf" } as const; | |
Test(oe2); | |
const oe3 = Object.freeze({ test: "haha", other: "asdf" }) | |
Test(oe3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment