From 78f39517cee54b2b3f2b48007af06ac0b2bc008c Mon Sep 17 00:00:00 2001 From: Jerko Steiner Date: Tue, 13 Aug 2019 10:20:34 +0700 Subject: [PATCH] Take into account alias type parameters --- packages/scripts/src/commands/typecheck.ts | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/scripts/src/commands/typecheck.ts b/packages/scripts/src/commands/typecheck.ts index bceda57..222eb59 100644 --- a/packages/scripts/src/commands/typecheck.ts +++ b/packages/scripts/src/commands/typecheck.ts @@ -93,11 +93,16 @@ export function typecheck(...argv: string[]) { // e.g. string or number types have no symbol return false } - if (symbol && !((symbol as any).parent)) { - // console.log(' no parent') - // e.g. Array symbol has no parent + if (symbol && symbol.flags & ts.SymbolFlags.Transient) { + console.log(' is transient') + // Array is transient. not sure if this is the best way to figure this return false } + // if (symbol && !((symbol as any).parent)) { + // // console.log(' no parent', symbol) + // // e.g. Array symbol has no parent + // return false + // } if (type.isLiteral()) { // console.log(' is literal') return false @@ -206,16 +211,16 @@ export function typecheck(...argv: string[]) { return } // if (type.aliasSymbol) { - // TODO figure out how to prevent iterating of properties from types - // such as strings + // // TODO figure out how to prevent iterating of properties from types + // // such as strings // return // } const typeParameters: ts.TypeParameter[] = [] const expandedTypeParameters: ts.Type[] = [] const allRelevantTypes: ts.Type[] = [] - if (type.isClassOrInterface() && type.typeParameters) { - type.typeParameters.forEach(tp => { + function handleTypeParameters(typeParams: readonly ts.Type[]) { + typeParams.forEach(tp => { const constraint = tp.getConstraint() if (constraint) { expandedTypeParameters.push(...getAllTypeParameters(tp)) @@ -229,6 +234,14 @@ export function typecheck(...argv: string[]) { }) } + if (type.isClassOrInterface() && type.typeParameters) { + handleTypeParameters(type.typeParameters) + } + + if (type.aliasSymbol && type.aliasTypeArguments) { + handleTypeParameters(type.aliasTypeArguments) + } + const properties = type.getApparentProperties() const filterClassTypeParameters =