typescript-is
Advanced tools
Comparing version
@@ -31,3 +31,3 @@ let defaultGetErrorObject = undefined; | ||
this.reason = errorObject.reason; | ||
this.input = inputObject | ||
this.input = inputObject; | ||
} | ||
@@ -34,0 +34,0 @@ } |
@@ -17,3 +17,3 @@ "use strict"; | ||
const properties = visitorContext.checker.getPropertiesOfType(type); | ||
const propertiesInfo = properties.map((property) => VisitorUtils.getPropertyInfo(property, visitorContext)); | ||
const propertiesInfo = properties.map((property) => VisitorUtils.getPropertyInfo(type, property, visitorContext)); | ||
const stringType = VisitorIsString.visitType(indexType, visitorContext); | ||
@@ -20,0 +20,0 @@ if (typeof stringType === 'boolean') { |
@@ -13,3 +13,3 @@ "use strict"; | ||
const properties = visitorContext.checker.getPropertiesOfType(type); | ||
const propertiesInfo = properties.map((property) => VisitorUtils.getPropertyInfo(property, visitorContext)); | ||
const propertiesInfo = properties.map((property) => VisitorUtils.getPropertyInfo(type, property, visitorContext)); | ||
const propertiesName = propertiesInfo.map((propertyInfo) => propertyInfo.name); | ||
@@ -16,0 +16,0 @@ return new Set(propertiesName); |
@@ -94,3 +94,3 @@ "use strict"; | ||
return VisitorUtils.setFunctionIfNotExists(name, visitorContext, () => { | ||
const propertyInfos = visitorContext.checker.getPropertiesOfType(type).map((property) => VisitorUtils.getPropertyInfo(property, visitorContext)); | ||
const propertyInfos = visitorContext.checker.getPropertiesOfType(type).map((property) => VisitorUtils.getPropertyInfo(type, property, visitorContext)); | ||
const stringIndexType = visitorContext.checker.getIndexTypeOfType(type, ts.IndexKind.String); | ||
@@ -97,0 +97,0 @@ const stringIndexFunctionName = stringIndexType ? visitType(stringIndexType, visitorContext) : undefined; |
@@ -9,3 +9,3 @@ import * as ts from 'typescript'; | ||
export declare function setFunctionIfNotExists(name: string, visitorContext: VisitorContext, factory: () => ts.FunctionDeclaration): string; | ||
export declare function getPropertyInfo(symbol: ts.Symbol, visitorContext: VisitorContext): { | ||
interface PropertyInfo { | ||
name: string; | ||
@@ -16,3 +16,4 @@ type: ts.Type | undefined; | ||
optional: boolean; | ||
}; | ||
} | ||
export declare function getPropertyInfo(parentType: ts.Type, symbol: ts.Symbol, visitorContext: VisitorContext): PropertyInfo; | ||
export declare function getTypeReferenceMapping(type: ts.TypeReference, visitorContext: VisitorContext): Map<ts.Type, ts.Type>; | ||
@@ -39,1 +40,2 @@ export declare function getResolvedTypeParameter(type: ts.Type, visitorContext: VisitorContext): ts.Type | undefined; | ||
export declare function createErrorObject(reason: Reason): ts.Expression; | ||
export {}; |
@@ -42,3 +42,3 @@ "use strict"; | ||
exports.setFunctionIfNotExists = setFunctionIfNotExists; | ||
function getPropertyInfo(symbol, visitorContext) { | ||
function getPropertyInfo(parentType, symbol, visitorContext) { | ||
const name = symbol.name; | ||
@@ -48,3 +48,7 @@ if (name === undefined) { | ||
} | ||
let propertyType = undefined; | ||
let isMethod = undefined; | ||
let optional = undefined; | ||
if ('valueDeclaration' in symbol) { | ||
// Attempt to get it from 'valueDeclaration' | ||
const valueDeclaration = symbol.valueDeclaration; | ||
@@ -54,3 +58,3 @@ if (!ts.isPropertySignature(valueDeclaration) && !ts.isMethodSignature(valueDeclaration)) { | ||
} | ||
const isMethod = ts.isMethodSignature(valueDeclaration); | ||
isMethod = ts.isMethodSignature(valueDeclaration); | ||
const isFunction = valueDeclaration.type !== undefined && ts.isFunctionTypeNode(valueDeclaration.type); | ||
@@ -63,3 +67,2 @@ if (isMethod && !visitorContext.options.ignoreMethods) { | ||
} | ||
let propertyType = undefined; | ||
if (valueDeclaration.type === undefined) { | ||
@@ -73,2 +76,17 @@ if (!isMethod) { | ||
} | ||
optional = !!valueDeclaration.questionToken; | ||
} | ||
else if ('type' in symbol) { | ||
// Attempt to get it from 'type' | ||
propertyType = symbol.type; | ||
isMethod = false; | ||
optional = (symbol.flags & ts.SymbolFlags.Optional) !== 0; | ||
} | ||
else if ('getTypeOfPropertyOfType' in visitorContext.checker) { | ||
// Attempt to get it from 'visitorContext.checker.getTypeOfPropertyOfType' | ||
propertyType = visitorContext.checker.getTypeOfPropertyOfType(parentType, name); | ||
isMethod = false; | ||
optional = (symbol.flags & ts.SymbolFlags.Optional) !== 0; | ||
} | ||
if (optional !== undefined && isMethod !== undefined) { | ||
return { | ||
@@ -79,21 +97,6 @@ name, | ||
isSymbol: name.startsWith('__@'), | ||
optional: !!valueDeclaration.questionToken | ||
optional | ||
}; | ||
} | ||
else { | ||
const propertyType = symbol.type; | ||
const optional = (symbol.flags & ts.SymbolFlags.Optional) !== 0; | ||
if (propertyType !== undefined) { | ||
return { | ||
name, | ||
type: propertyType, | ||
isMethod: false, | ||
isSymbol: name.startsWith('__@'), | ||
optional | ||
}; | ||
} | ||
else { | ||
throw new Error('Expected a valueDeclaration or a property type.'); | ||
} | ||
} | ||
throw new Error('Expected a valueDeclaration or a property type.'); | ||
} | ||
@@ -100,0 +103,0 @@ exports.getPropertyInfo = getPropertyInfo; |
{ | ||
"name": "typescript-is", | ||
"version": "0.16.1", | ||
"version": "0.16.2", | ||
"engines": { | ||
@@ -56,4 +56,4 @@ "node": ">=6.14.4" | ||
"ttypescript": "^1.5.10", | ||
"typescript": "^3.7.5" | ||
"typescript": "^3.9.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
221852
0.33%2711
0.18%