diff --git a/__tests__/__snapshots__/test.js.snap b/__tests__/__snapshots__/test.js.snap index 0ad23c1b9..8d975269e 100644 --- a/__tests__/__snapshots__/test.js.snap +++ b/__tests__/__snapshots__/test.js.snap @@ -31972,30 +31972,6 @@ Array [ "tags": Array [], "throws": Array [], "todos": Array [], - "type": Object { - "fields": Array [ - Object { - "key": "opt", - "type": "FieldType", - "value": Object { - "expression": Object { - "name": "number", - "type": "NameExpression", - }, - "type": "OptionalType", - }, - }, - Object { - "key": "req", - "type": "FieldType", - "value": Object { - "name": "string", - "type": "NameExpression", - }, - }, - ], - "type": "RecordType", - }, "yields": Array [], }, ] @@ -32011,8 +31987,6 @@ exports[`outputs optional-record-field-type.input.js markdown 1`] = ` ## Record -Type: {opt: [number][3]?, req: [string][4]} - ### Properties - \`opt\` **[number][3]?** @@ -32045,61 +32019,6 @@ Object { "depth": 2, "type": "heading", }, - Object { - "children": Array [ - Object { - "type": "text", - "value": "Type: ", - }, - Object { - "type": "text", - "value": "{", - }, - Object { - "type": "text", - "value": "opt: ", - }, - Object { - "children": Array [ - Object { - "type": "text", - "value": "number", - }, - ], - "identifier": "1", - "referenceType": "full", - "type": "linkReference", - }, - Object { - "type": "text", - "value": "?", - }, - Object { - "type": "text", - "value": ", ", - }, - Object { - "type": "text", - "value": "req: ", - }, - Object { - "children": Array [ - Object { - "type": "text", - "value": "string", - }, - ], - "identifier": "2", - "referenceType": "full", - "type": "linkReference", - }, - Object { - "type": "text", - "value": "}", - }, - ], - "type": "paragraph", - }, Object { "children": Array [ Object { diff --git a/__tests__/lib/infer/type.js b/__tests__/lib/infer/type.js index 19ea0dc18..beab3d0ee 100644 --- a/__tests__/lib/infer/type.js +++ b/__tests__/lib/infer/type.js @@ -41,28 +41,6 @@ test('inferType (flow)', function() { type: 'TypeApplication' }); - expect(evaluate('/** */' + "type V = {a:number,'b':string}").type).toEqual({ - fields: [ - { - key: 'a', - type: 'FieldType', - value: { - name: 'number', - type: 'NameExpression' - } - }, - { - key: 'b', - type: 'FieldType', - value: { - name: 'string', - type: 'NameExpression' - } - } - ], - type: 'RecordType' - }); - expect(evaluate('/** */' + 'type V = Array').type).toEqual({ applications: [ { @@ -127,16 +105,12 @@ test('inferType (flow)', function() { type: 'NameExpression' }); - expect( - evaluate('interface Foo { /** */ bar: string; }').type - ).toEqual({ + expect(evaluate('interface Foo { /** */ bar: string; }').type).toEqual({ name: 'string', type: 'NameExpression' }); - expect( - evaluate('type Foo = { /** */ bar: string; }').type - ).toEqual({ + expect(evaluate('type Foo = { /** */ bar: string; }').type).toEqual({ name: 'string', type: 'NameExpression' }); @@ -167,28 +141,6 @@ test('inferType (typescript)', function() { type: 'TypeApplication' }); - expect(evaluate('/** */' + "type V = {a:number,'b':string}", 'test.ts').type).toEqual({ - fields: [ - { - key: 'a', - type: 'FieldType', - value: { - name: 'number', - type: 'NameExpression' - } - }, - { - key: 'b', - type: 'FieldType', - value: { - name: 'string', - type: 'NameExpression' - } - } - ], - type: 'RecordType' - }); - expect(evaluate('/** */' + 'type V = Array', 'test.ts').type).toEqual({ applications: [ { @@ -223,27 +175,43 @@ test('inferType (typescript)', function() { type: 'NameExpression' }); - expect(evaluate('class C {' + '/** */' + 'x: number;' + '}', 'test.ts').type).toEqual({ + expect( + evaluate('class C {' + '/** */' + 'x: number;' + '}', 'test.ts').type + ).toEqual({ name: 'number', type: 'NameExpression' }); - expect(evaluate('class Foo { /** */ get b(): string { } }', 'test.ts').type).toEqual({ + expect( + evaluate('class Foo { /** */ get b(): string { } }', 'test.ts').type + ).toEqual({ name: 'string', type: 'NameExpression' }); - expect(evaluate('class Foo { /** */ set b(s: string) { } }', 'test.ts').type).toEqual({ + expect( + evaluate('class Foo { /** */ set b(s: string) { } }', 'test.ts').type + ).toEqual({ name: 'string', type: 'NameExpression' }); - expect(evaluate('abstract class Foo { /** */ abstract get b(): string; }', 'test.ts').type).toEqual({ + expect( + evaluate( + 'abstract class Foo { /** */ abstract get b(): string; }', + 'test.ts' + ).type + ).toEqual({ name: 'string', type: 'NameExpression' }); - expect(evaluate('abstract class Foo { /** */ abstract set b(s: string); }', 'test.ts').type).toEqual({ + expect( + evaluate( + 'abstract class Foo { /** */ abstract set b(s: string); }', + 'test.ts' + ).type + ).toEqual({ name: 'string', type: 'NameExpression' }); @@ -277,28 +245,22 @@ test('inferType (typescript)', function() { type: 'NameExpression' }); - expect( - evaluate('enum Foo { /** */ A }', 'test.ts').type - ).toEqual({ + expect(evaluate('enum Foo { /** */ A }', 'test.ts').type).toEqual({ name: 'number', type: 'NameExpression' }); - expect( - evaluate('enum Foo { /** */ A = 2 }', 'test.ts').type - ).toEqual({ + expect(evaluate('enum Foo { /** */ A = 2 }', 'test.ts').type).toEqual({ name: 'number', type: 'NameExpression' }); - expect( - evaluate('enum Foo { /** */ A = "test" }', 'test.ts').type - ).toEqual({ + expect(evaluate('enum Foo { /** */ A = "test" }', 'test.ts').type).toEqual({ name: 'string', type: 'NameExpression' }); - expect( - evaluate('enum Foo { /** */ A = foo }', 'test.ts').type - ).toBe(undefined); + expect(evaluate('enum Foo { /** */ A = foo }', 'test.ts').type).toBe( + undefined + ); }); diff --git a/src/infer/type.js b/src/infer/type.js index 0dfb45917..faa3b7259 100644 --- a/src/infer/type.js +++ b/src/infer/type.js @@ -64,7 +64,9 @@ function inferType(comment) { type = ast.node.value; } } - if (type) { + // Don't provide a `type` section when it's an ObjectTypeAnnotation, + // `properties` already exists and renders better. + if (type && type.type !== 'ObjectTypeAnnotation') { comment.type = typeAnnotation(type); } return comment;