ts-auto-guard
Advanced tools
Comparing version 1.0.0-alpha.25 to 1.0.0-alpha.26
@@ -398,3 +398,3 @@ "use strict"; | ||
} | ||
if (type.getText() === 'any') { | ||
if (type.getText() === 'any' || type.getText() === 'unknown') { | ||
return null; | ||
@@ -401,0 +401,0 @@ } |
{ | ||
"name": "ts-auto-guard", | ||
"version": "1.0.0-alpha.25", | ||
"version": "1.0.0-alpha.26", | ||
"description": "Generate type guard functions from TypeScript interfaces", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/rhys-vdw/ts-auto-guard", |
@@ -1344,1 +1344,55 @@ import test from 'tape' | ||
) | ||
testProcessProject( | ||
'Deals with unknown type as it would any', | ||
{ | ||
'test.ts': ` | ||
/** @see {isTestType} ts-auto-guard:type-guard */ | ||
export interface TestType { | ||
[index: string]: unknown | ||
} | ||
`, | ||
}, | ||
{ | ||
'test.ts': null, | ||
'test.guard.ts': ` | ||
import { TestType } from "./test"; | ||
export function isTestType(obj: any, _argumentName?: string): obj is TestType { | ||
return ( | ||
(obj !== null && | ||
typeof obj === "object" || | ||
typeof obj === "function") && | ||
Object.entries(obj) | ||
.every(([key, _value]) => (typeof key === "string")) | ||
) | ||
} | ||
`, | ||
} | ||
) | ||
testProcessProject( | ||
'Deals with unknown type as it would any', | ||
{ | ||
'test.ts': ` | ||
/** @see {isTestType} ts-auto-guard:type-guard */ | ||
export interface TestType { | ||
test: unknown | ||
} | ||
`, | ||
}, | ||
{ | ||
'test.ts': null, | ||
'test.guard.ts': ` | ||
import { TestType } from "./test"; | ||
export function isTestType(obj: any, _argumentName?: string): obj is TestType { | ||
return ( | ||
(obj !== null && | ||
typeof obj === "object" || | ||
typeof obj === "function") | ||
) | ||
} | ||
`, | ||
} | ||
) |
Sorry, the diff of this file is not supported yet
119560
2310