-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #227 from samchon/v3.3
Fix #226 - consider meta-programmed class type
- Loading branch information
Showing
4 changed files
with
46 additions
and
1 deletion.
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
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 @@ | ||
import TSON from "../../src"; | ||
|
||
type DeepPartial<T> = T extends object | ||
? { | ||
[P in keyof T]?: DeepPartial<T[P]>; | ||
} | ||
: T; | ||
|
||
const input = { a: "valid" }; | ||
|
||
console.log("Works with interface:"); | ||
|
||
interface TestInterface { | ||
a: string; | ||
} | ||
|
||
const res = TSON.validateEquals<TestInterface>(input); | ||
console.log("valid:", res); | ||
|
||
const res2 = TSON.validateEquals<Partial<TestInterface>>(input); | ||
console.log("valid:", res2); | ||
|
||
const res3 = TSON.validateEquals<DeepPartial<TestInterface>>(input); | ||
console.log("valid:", res3); | ||
|
||
console.log(""); | ||
console.log("---------------------------"); | ||
console.log(""); | ||
|
||
console.log("Does not work with declare class:"); | ||
|
||
declare class TestClass { | ||
a: string; | ||
} | ||
|
||
const res4 = TSON.validateEquals<TestClass>(input); | ||
console.log("valid:", res4); | ||
|
||
const res5 = TSON.validateEquals<Partial<TestClass>>(input); | ||
console.log("should be valid:", res5); | ||
|
||
const res6 = TSON.validateEquals<DeepPartial<TestClass>>(input); | ||
console.log("should be invalid:", res6); |