MCPcopy Create free account
hub / github.com/coder/guts / buildUnion

Method buildUnion

convert.go:1279–1302  ·  view source on GitHub ↗

buildStruct just prints the typescript def for a type.

(obj types.Object, st *types.Union)

Source from the content-addressed store, hash-verified

1277
1278// buildStruct just prints the typescript def for a type.
1279func (ts *Typescript) buildUnion(obj types.Object, st *types.Union) (*bindings.Alias, error) {
1280 alias := &bindings.Alias{
1281 Name: ts.parsed.Identifier(obj),
1282 Modifiers: []bindings.Modifier{},
1283 Type: nil,
1284 Parameters: nil,
1285 Source: ts.location(obj),
1286 }
1287
1288 allTypes := make([]bindings.ExpressionType, 0, st.Len())
1289 for i := 0; i < st.Len(); i++ {
1290 term := st.Term(i)
1291 scriptType, err := ts.typescriptType(term.Type())
1292 if err != nil {
1293 return alias, xerrors.Errorf("union %q for %q failed to get type: %w", st.String(), obj.Name(), err)
1294 }
1295 // TODO: Generics
1296 // scriptType.TypeParameters
1297 allTypes = append(allTypes, scriptType.Value)
1298 }
1299
1300 alias.Type = bindings.Union(allTypes...)
1301 return alias, nil
1302}
1303
1304// typeParametersParameters extracts the generic parameters from a named type.
1305func (ts *Typescript) typeParametersParameters(obj interface{ TypeParams() *types.TypeParamList }) ([]*bindings.TypeParameter, error) {

Callers 1

parseMethod · 0.95

Calls 5

locationMethod · 0.95
typescriptTypeMethod · 0.95
UnionFunction · 0.92
IdentifierMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected