-
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #573 - exact import path generation
- Loading branch information
Showing
16 changed files
with
291 additions
and
359 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
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 |
---|---|---|
@@ -1,13 +1,26 @@ | ||
import typia from "../../../src"; | ||
import { ObjectPrimitive } from "../../structures/ObjectPrimitive"; | ||
|
||
interface A { | ||
a: string; | ||
} | ||
interface B { | ||
b: string; | ||
} | ||
type Union = A | B; | ||
|
||
export const checkUnion = typia.createIs<Union>(); | ||
export const checkPrimitive = typia.createIs<ObjectPrimitive>(); | ||
export const checkUnion = (input: any): input is Union => { | ||
const $io0 = (input: any): boolean => "string" === typeof input.a; | ||
const $io1 = (input: any): boolean => "string" === typeof input.b; | ||
const $iu0 = (input: any): any => (() => { | ||
if (undefined !== input.a) | ||
return $io0(input); | ||
if (undefined !== input.b) | ||
return $io1(input); | ||
return false; | ||
})(); | ||
return "object" === typeof input && null !== input && $iu0(input); | ||
}; | ||
export const checkPrimitive = (input: any): input is ObjectPrimitive => { | ||
const $io0 = (input: any): boolean => "string" === typeof input.id && ("md" === input.extension || "html" === input.extension || "txt" === input.extension) && "string" === typeof input.title && "string" === typeof input.body && (Array.isArray(input.files) && input.files.every((elem: any) => "object" === typeof elem && null !== elem && $io1(elem))) && "boolean" === typeof input.secret && "string" === typeof input.created_at; | ||
const $io1 = (input: any): boolean => "string" === typeof input.id && "string" === typeof input.name && "string" === typeof input.extension && "string" === typeof input.url && "string" === typeof input.created_at; | ||
return "object" === typeof input && null !== input && $io0(input); | ||
}; |
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 typia from "../../../src"; | ||
import { ISomeOutputDto } from "./structures/ISomeOutputDto"; | ||
export const isSomeOutputDto = (input: any): ISomeOutputDto => { | ||
const $guard = (typia.createAssert as any).guard; | ||
const $is_uuid = (typia.createAssert as any).is_uuid; | ||
((input: any, _path: string, _exceptionable: boolean = true): input is ISomeOutputDto => { | ||
const $ao0 = (input: any, _path: string, _exceptionable: boolean = true): boolean => ("string" === typeof input.id && (true === $is_uuid(input.id) || $guard(_exceptionable, { | ||
path: _path + ".id", | ||
expected: "string (@format uuid)", | ||
value: input.id | ||
})) || $guard(_exceptionable, { | ||
path: _path + ".id", | ||
expected: "string", | ||
value: input.id | ||
})) && ("string" === typeof input.name && (3 <= input.name.length || $guard(_exceptionable, { | ||
path: _path + ".name", | ||
expected: "string (@minLength 3)", | ||
value: input.name | ||
})) || $guard(_exceptionable, { | ||
path: _path + ".name", | ||
expected: "string", | ||
value: input.name | ||
})) && ("number" === typeof input.age && (0 <= input.age || $guard(_exceptionable, { | ||
path: _path + ".age", | ||
expected: "number (@minimum 0)", | ||
value: input.age | ||
})) && (100 >= input.age || $guard(_exceptionable, { | ||
path: _path + ".age", | ||
expected: "number (@maximum 100)", | ||
value: input.age | ||
})) || $guard(_exceptionable, { | ||
path: _path + ".age", | ||
expected: "number", | ||
value: input.age | ||
})); | ||
return ("object" === typeof input && null !== input || $guard(true, { | ||
path: _path + "", | ||
expected: "Resolve<ISomeOutputDto>", | ||
value: input | ||
})) && $ao0(input, _path + "", true); | ||
})(input, "$input", true); | ||
return input; | ||
}; |
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,9 @@ | ||
import typia from "../../../src"; | ||
const values = [ | ||
true, | ||
"A", | ||
"B", | ||
1, | ||
2 | ||
] as const; | ||
console.log(values); |
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,13 @@ | ||
import typia from "../../../../src"; | ||
import { ObjectPrimitive } from "../../../structures/ObjectPrimitive"; | ||
|
||
interface A { | ||
a: string; | ||
} | ||
interface B { | ||
b: string; | ||
} | ||
type Union = A | B; | ||
|
||
export const checkUnion = typia.createIs<Union>(); | ||
export const checkPrimitive = typia.createIs<ObjectPrimitive>(); |
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,4 @@ | ||
import typia from "../../../../src"; | ||
import { ISomeOutputDto } from "../structures/ISomeOutputDto"; | ||
|
||
export const isSomeOutputDto = typia.createAssert<ISomeOutputDto>(); |
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,4 @@ | ||
import typia from "../../../../src"; | ||
|
||
const values = typia.literals<true | "A" | "B" | 1 | 2>(); | ||
console.log(values); |
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,50 @@ | ||
import typia from "../../../../src"; | ||
|
||
const ERROR = { | ||
TOO_LONG_KEY_NAME1: { | ||
result: false, | ||
code: 4000, | ||
data: "Error happens something1.", | ||
}, | ||
TOO_LONG_KEY_NAME2: { | ||
result: false, | ||
code: 4000, | ||
data: "Error happens something2.", | ||
}, | ||
TOO_LONG_KEY_NAME3: { | ||
result: false, | ||
code: 4000, | ||
data: "Error happens something3.", | ||
}, | ||
TOO_LONG_KEY_NAME4: { | ||
result: false, | ||
code: 4000, | ||
data: "Error happens something4.", | ||
}, | ||
TOO_LONG_KEY_NAME5: { | ||
result: false, | ||
code: 4000, | ||
data: "Error happens something5.", | ||
}, | ||
} as const; | ||
|
||
type KeyOfError = keyof typeof ERROR; | ||
type ValueOfError = (typeof ERROR)[KeyOfError]; | ||
interface ResponseForm<T> { | ||
result: true; | ||
code: 1000; | ||
data: T; | ||
} | ||
|
||
type Try<T, E extends ValueOfError> = ResponseForm<T> | E; | ||
|
||
const input: Try< | ||
true, | ||
| typeof ERROR.TOO_LONG_KEY_NAME1 | ||
| typeof ERROR.TOO_LONG_KEY_NAME2 | ||
| typeof ERROR.TOO_LONG_KEY_NAME3 | ||
| typeof ERROR.TOO_LONG_KEY_NAME4 | ||
| typeof ERROR.TOO_LONG_KEY_NAME5 | ||
> = {} as any; | ||
|
||
typia.assert(input); |
Oops, something went wrong.