buildStruct just prints the typescript def for a type.
(obj types.Object, st *types.Union)
| 1277 | |
| 1278 | // buildStruct just prints the typescript def for a type. |
| 1279 | func (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. |
| 1305 | func (ts *Typescript) typeParametersParameters(obj interface{ TypeParams() *types.TypeParamList }) ([]*bindings.TypeParameter, error) { |
no test coverage detected