Add getAllTypeParameters (not fully impl)
This commit is contained in:
parent
0ce76eb648
commit
515232c458
@ -18,7 +18,7 @@ export class Name {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IYear {
|
export interface IYear {
|
||||||
year: number
|
yeak: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ITyped<T> {
|
export interface ITyped<T> {
|
||||||
|
|||||||
@ -32,10 +32,50 @@ export function typecheck() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
function getAllTypeParameters(type: ts.Type) {
|
function getAllTypeParameters(type: ts.Type): ts.Type[] {
|
||||||
// checker.typeToTypeNode
|
console.log('TTT', checker.typeToString(type), {
|
||||||
// ts.isParameterPropertyDeclaration(type.
|
isClassOrInterface: type.isClassOrInterface(),
|
||||||
// if (type.
|
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 */
|
/** visit nodes finding exported classes */
|
||||||
@ -103,10 +143,13 @@ export function typecheck() {
|
|||||||
|
|
||||||
p.flags
|
p.flags
|
||||||
|
|
||||||
|
console.log('---')
|
||||||
return {
|
return {
|
||||||
name: p.getName(),
|
name: p.getName(),
|
||||||
type: checker.typeToString(propType),
|
type: checker.typeToString(propType),
|
||||||
questionToken,
|
questionToken,
|
||||||
|
typeParams: getAllTypeParameters(propType).map(
|
||||||
|
t => checker.typeToString(t)),
|
||||||
// classOrIface: propType.isClassOrInterface(),
|
// classOrIface: propType.isClassOrInterface(),
|
||||||
// union: propType.isUnion(),
|
// union: propType.isUnion(),
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user