Skip to content

Commit

Permalink
Merge pull request #227 from samchon/v3.3
Browse files Browse the repository at this point in the history
Fix #226 - consider meta-programmed class type
  • Loading branch information
samchon authored Oct 7, 2022
2 parents 5cd11d6 + 4c45595 commit f35c7ff
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json",
"version": "3.3.6",
"version": "3.3.7",
"description": "Runtime type checkers and 5x faster JSON.stringify() function",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/factories/internal/emplace_metadata_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const emplace_metadata_object =
const pred: (node: ts.Declaration) => boolean = isClass
? (node) => ts.isParameter(node) || ts.isPropertyDeclaration(node)
: (node) =>
ts.isPropertyDeclaration(node) ||
ts.isPropertyAssignment(node) ||
ts.isPropertySignature(node) ||
ts.isTypeLiteralNode(node);
Expand Down
1 change: 1 addition & 0 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default function transform(
program: ts.Program,
options?: ITransformOptions,
): ts.TransformerFactory<ts.SourceFile> {
program.getSourceFiles().map(file => file.fileName);
const project: IProject = {
program,
compilerOptions: program.getCompilerOptions(),
Expand Down
43 changes: 43 additions & 0 deletions test/issues/226.ts
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);

0 comments on commit f35c7ff

Please sign in to comment.