Add getAllTypeParameters (not fully impl)

This commit is contained in:
Jerko Steiner 2019-08-12 09:50:19 +07:00
parent 0ce76eb648
commit 515232c458
2 changed files with 48 additions and 5 deletions

View File

@ -18,7 +18,7 @@ export class Name {
}
export interface IYear {
year: number
yeak: number
}
export interface ITyped<T> {

View File

@ -32,10 +32,50 @@ export function typecheck() {
}
return
function getAllTypeParameters(type: ts.Type) {
// checker.typeToTypeNode
// ts.isParameterPropertyDeclaration(type.
// if (type.
function getAllTypeParameters(type: ts.Type): ts.Type[] {
console.log('TTT', checker.typeToString(type), {
isClassOrInterface: type.isClassOrInterface(),
isUnionOrIntersection: type.isUnionOrIntersection(),
isTypeParameter: type.isTypeParameter(),
isLiteral: type.isLiteral(),
aliasTypeArguments: type.aliasTypeArguments,
// baseCon: checker.typeToString(checker.getBaseConstraintOfType(type)),
})
if (type.isUnionOrIntersection()) {
// console.log('TTT isUnionOrIntersection')
const types = [type, ...type.types]
type.types.forEach(t => {
const tsp = getAllTypeParameters(t)
types.push(...tsp)
})
return types
}
// type.
if (type.isClassOrInterface()) {
// console.log('TTT isClassOrInterface')
if (type.typeParameters) {
// console.log('TTT typeParameters')
const types = [type, ...type.typeParameters]
type.typeParameters.forEach(t => {
const tsp = getAllTypeParameters(t)
types.push(...tsp)
})
return types
}
return [type]
}
// if (type.isIntersection()) {
// }
// if (type.isTypeParameter()) {
// console.log('AAAAAAAAAAAAAAAAAAAAAAAAAAAA')
// }
return [type]
}
/** visit nodes finding exported classes */
@ -103,10 +143,13 @@ export function typecheck() {
p.flags
console.log('---')
return {
name: p.getName(),
type: checker.typeToString(propType),
questionToken,
typeParams: getAllTypeParameters(propType).map(
t => checker.typeToString(t)),
// classOrIface: propType.isClassOrInterface(),
// union: propType.isUnion(),
}