Skip to content

refactor: 💡 type section is redundant and not formatted #1327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 0 additions & 81 deletions __tests__/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 [],
},
]
Expand All @@ -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]?**
Expand Down Expand Up @@ -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 {
Expand Down
96 changes: 29 additions & 67 deletions __tests__/lib/infer/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>').type).toEqual({
applications: [
{
Expand Down Expand Up @@ -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'
});
Expand Down Expand Up @@ -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<T>', 'test.ts').type).toEqual({
applications: [
{
Expand Down Expand Up @@ -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'
});
Expand Down Expand Up @@ -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
);
});
4 changes: 3 additions & 1 deletion src/infer/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down