Recursively expand type references
This commit is contained in:
parent
515232c458
commit
3937778e06
@ -33,18 +33,34 @@ export function typecheck() {
|
|||||||
|
|
||||||
return
|
return
|
||||||
function getAllTypeParameters(type: ts.Type): ts.Type[] {
|
function getAllTypeParameters(type: ts.Type): ts.Type[] {
|
||||||
console.log('TTT', checker.typeToString(type), {
|
console.log('TTT', checker.typeToString(type),
|
||||||
isClassOrInterface: type.isClassOrInterface(),
|
{
|
||||||
isUnionOrIntersection: type.isUnionOrIntersection(),
|
isObject: !!(type.flags & ts.TypeFlags.Object),
|
||||||
isTypeParameter: type.isTypeParameter(),
|
isTuple: (type as any).objectFlags & ts.ObjectFlags.Tuple,
|
||||||
isLiteral: type.isLiteral(),
|
objectFlags: (type as any).objectFlags,
|
||||||
aliasTypeArguments: type.aliasTypeArguments,
|
},
|
||||||
// baseCon: checker.typeToString(checker.getBaseConstraintOfType(type)),
|
)
|
||||||
})
|
if (type.flags & ts.TypeFlags.Object) {
|
||||||
|
const objectType = type as ts.ObjectType
|
||||||
|
const objectFlags = objectType.objectFlags
|
||||||
|
if (objectFlags & ts.ObjectFlags.Reference) {
|
||||||
|
const types = [type]
|
||||||
|
const typeRef = type as ts.TypeReference
|
||||||
|
if (typeRef.typeArguments) {
|
||||||
|
typeRef.typeArguments.forEach(t => {
|
||||||
|
const ta = getAllTypeParameters(t)
|
||||||
|
types.push(...ta)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return types
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (type.isUnionOrIntersection()) {
|
if (type.isUnionOrIntersection()) {
|
||||||
// console.log('TTT isUnionOrIntersection')
|
// console.log('TTT isUnionOrIntersection')
|
||||||
const types = [type, ...type.types]
|
const unionOrIntersectionTypes = type.types
|
||||||
|
// const types = [type, ...type.types]
|
||||||
|
const types: ts.Type[] = [type]
|
||||||
type.types.forEach(t => {
|
type.types.forEach(t => {
|
||||||
const tsp = getAllTypeParameters(t)
|
const tsp = getAllTypeParameters(t)
|
||||||
types.push(...tsp)
|
types.push(...tsp)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user