MCPcopy Index your code
hub / github.com/microsoft/typescript-go / getArrayMemberCallSignatures

Method getArrayMemberCallSignatures

internal/checker/checker.go:20976–20997  ·  view source on GitHub ↗
(t *Type)

Source from the content-addressed store, hash-verified

20974}
20975
20976func (c *Checker) getArrayMemberCallSignatures(t *Type) []*Signature {
20977 // Check if union is exclusively instantiations of a member of the global Array or ReadonlyArray type.
20978 var memberName string
20979 for i, t := range t.Types() {
20980 if t.objectFlags&ObjectFlagsInstantiated == 0 || t.symbol == nil || t.symbol.Parent == nil || !c.isArrayOrTupleSymbol(t.symbol.Parent) {
20981 return nil
20982 }
20983 if i == 0 {
20984 memberName = t.symbol.Name
20985 } else if memberName != t.symbol.Name {
20986 return nil
20987 }
20988 }
20989 // Transform the type from `(A[] | B[])["member"]` to `(A | B)[]["member"]` (since we pretend array is covariant anyway).
20990 arrayArg := c.mapType(t, func(t *Type) *Type {
20991 return t.Mapper().Map(core.IfElse(c.isReadonlyArraySymbol(t.symbol.Parent), c.globalReadonlyArrayType, c.globalArrayType).AsInterfaceType().TypeParameters()[0])
20992 })
20993 arrayType := c.createArrayTypeEx(arrayArg, someType(t, func(t *Type) bool {
20994 return c.isReadonlyArraySymbol(t.symbol.Parent)
20995 }))
20996 return c.getSignaturesOfType(c.getTypeOfPropertyOfType(arrayType, memberName), SignatureKindCall)
20997}
20998
20999func (c *Checker) isArrayOrTupleSymbol(symbol *ast.Symbol) bool {
21000 if symbol == nil || c.globalArrayType.symbol == nil || c.globalReadonlyArrayType.symbol == nil {

Callers 1

Calls 13

isArrayOrTupleSymbolMethod · 0.95
mapTypeMethod · 0.95
isReadonlyArraySymbolMethod · 0.95
createArrayTypeExMethod · 0.95
getSignaturesOfTypeMethod · 0.95
IfElseFunction · 0.92
someTypeFunction · 0.85
MapperMethod · 0.80
MapMethod · 0.65
AsInterfaceTypeMethod · 0.65
TypesMethod · 0.45

Tested by

no test coverage detected