Skip to content

Commit a9fa0fc

Browse files
Adopt Strada-style object type printing. (microsoft#433)
1 parent 0c22cba commit a9fa0fc

File tree

3 files changed

+16
-24
lines changed

3 files changed

+16
-24
lines changed

internal/checker/printer.go

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -364,27 +364,20 @@ func (p *Printer) printAnonymousType(t *Type) {
364364
}
365365
}
366366
p.print("{")
367-
var tail bool
367+
hasMembers := false
368368
for _, sig := range callSignatures {
369-
if tail {
370-
p.print(",")
371-
}
372369
p.print(" ")
373370
p.printSignature(sig, ": ")
374-
tail = true
371+
p.print(";")
372+
hasMembers = true
375373
}
376374
for _, sig := range constructSignatures {
377-
if tail {
378-
p.print(",")
379-
}
380375
p.print(" new")
381376
p.printSignature(sig, ": ")
382-
tail = true
377+
p.print(";")
378+
hasMembers = true
383379
}
384380
for _, info := range p.c.getIndexInfosOfType(t) {
385-
if tail {
386-
p.print(",")
387-
}
388381
if info.isReadonly {
389382
p.print(" readonly")
390383
}
@@ -394,12 +387,10 @@ func (p *Printer) printAnonymousType(t *Type) {
394387
p.printType(info.keyType)
395388
p.print("]: ")
396389
p.printType(info.valueType)
397-
tail = true
390+
p.print(";")
391+
hasMembers = true
398392
}
399393
for _, prop := range props {
400-
if tail {
401-
p.print(",")
402-
}
403394
if p.c.isReadonlySymbol(prop) {
404395
p.print(" readonly")
405396
}
@@ -410,9 +401,10 @@ func (p *Printer) printAnonymousType(t *Type) {
410401
}
411402
p.print(": ")
412403
p.printType(p.c.getTypeOfSymbol(prop))
413-
tail = true
404+
p.print(";")
405+
hasMembers = true
414406
}
415-
if tail {
407+
if hasMembers {
416408
p.print(" ")
417409
}
418410
p.print("}")

testdata/baselines/reference/compiler/allowSyntheticDefaultImports9.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ export function bar();
99

1010
=== a.ts ===
1111
import { default as Foo } from "./b";
12-
>default : { foo: () => any, bar: () => any }
13-
>Foo : { foo: () => any, bar: () => any }
12+
>default : { foo: () => any; bar: () => any; }
13+
>Foo : { foo: () => any; bar: () => any; }
1414

1515
Foo.bar();
1616
>Foo.bar() : any
1717
>Foo.bar : () => any
18-
>Foo : { foo: () => any, bar: () => any }
18+
>Foo : { foo: () => any; bar: () => any; }
1919
>bar : () => any
2020

2121
Foo.foo();
2222
>Foo.foo() : any
2323
>Foo.foo : () => any
24-
>Foo : { foo: () => any, bar: () => any }
24+
>Foo : { foo: () => any; bar: () => any; }
2525
>foo : () => any
2626

testdata/baselines/reference/compiler/symbolLinkDeclarationEmitModuleNamesRootDir.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import { ControllerClass } from './application';
1212
>ControllerClass : error
1313

1414
import { BindingKey } from '@loopback/context';
15-
>BindingKey : { new<T>(): BindingKey<T>, create: <T>(ctor: T) => BindingKey<T>, prototype: BindingKey<any> }
15+
>BindingKey : { new<T>(): BindingKey<T>; create: <T>(ctor: T) => BindingKey<T>; prototype: BindingKey<any>; }
1616

1717
export const CONTROLLER_CLASS = BindingKey.create<ControllerClass>(null as any); // line in question
1818
>CONTROLLER_CLASS : BindingKey<ControllerClass>
1919
>BindingKey.create<ControllerClass>(null as any) : BindingKey<ControllerClass>
2020
>BindingKey.create : <T>(ctor: T) => BindingKey<T>
21-
>BindingKey : { new<T>(): BindingKey<T>, create: <T>(ctor: T) => BindingKey<T>, prototype: BindingKey<any> }
21+
>BindingKey : { new<T>(): BindingKey<T>; create: <T>(ctor: T) => BindingKey<T>; prototype: BindingKey<any>; }
2222
>create : <T>(ctor: T) => BindingKey<T>
2323
>null as any : any
2424

0 commit comments

Comments
 (0)