typescript-is
Advanced tools
Comparing version 0.6.7 to 0.7.0
@@ -169,3 +169,3 @@ "use strict"; | ||
} | ||
function visitNonPrimitive(type, accessor, visitorContext) { | ||
function visitNonPrimitiveType(type, accessor, visitorContext) { | ||
const intrinsicName = type.intrinsicName; | ||
@@ -197,2 +197,21 @@ let conditions; | ||
} | ||
function visitIndexType(type, accessor, visitorContext) { | ||
const typeMapper = visitorContext.typeMapperStack[visitorContext.typeMapperStack.length - 1]; | ||
// Using internal TypeScript API, hacky. | ||
let indexedType = type.type; | ||
if (indexedType === undefined) { | ||
throw new Error('Could not get indexed type of index type.'); | ||
} | ||
// Make sure we resolve type parameters. | ||
indexedType = typeMapper(indexedType) || indexedType; | ||
const properties = visitorContext.checker.getPropertiesOfType(indexedType); | ||
if (properties.length >= 1) { | ||
return properties | ||
.map((property) => ts.createStrictEquality(accessor, ts.createStringLiteral(property.name))) | ||
.reduce((condition, expression) => ts.createBinary(condition, ts.SyntaxKind.BarBarToken, expression)); | ||
} | ||
else { | ||
return ts.createFalse(); | ||
} | ||
} | ||
function visitType(type, accessor, visitorContext) { | ||
@@ -249,4 +268,8 @@ if ((ts.TypeFlags.Any & type.flags) !== 0) { | ||
// Non-primitive such as object | ||
return visitNonPrimitive(type, accessor, visitorContext); | ||
return visitNonPrimitiveType(type, accessor, visitorContext); | ||
} | ||
else if ((ts.TypeFlags.Index & type.flags) !== 0) { | ||
// Index type: keyof X | ||
return visitIndexType(type, accessor, visitorContext); | ||
} | ||
else { | ||
@@ -253,0 +276,0 @@ throw new Error('Unsupported type with flags: ' + type.flags); |
{ | ||
"name": "typescript-is", | ||
"version": "0.6.7", | ||
"version": "0.7.0", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=6.14.4" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75343
780