Skip to content

Commit

Permalink
fix: ts error on src/argTypes/docgen/flow folder
Browse files Browse the repository at this point in the history
  • Loading branch information
efrenaragon96 committed May 16, 2023
1 parent d59b019 commit cb673d8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function createDefaultValue(
if (!isDefaultValueBlacklisted(value)) {
return !isTooLongForDefaultValueSummary(value)
? createSummaryValue(value)
: createSummaryValue(type.name, value);
: createSummaryValue(type?.name, value);
}
}

Expand Down
40 changes: 20 additions & 20 deletions code/lib/docs-tools/src/argTypes/docgen/flow/createPropDef.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function createDocgenInfo({ flowType, ...others }: Partial<DocgenInfo>): DocgenI
flowType,
required: false,
...others,
};
} as DocgenInfo;
}

describe('type', () => {
Expand All @@ -21,8 +21,8 @@ describe('type', () => {

const { type } = createFlowPropDef(PROP_NAME, docgenInfo);

expect(type.summary).toBe(x);
expect(type.detail).toBeUndefined();
expect(type?.summary).toBe(x);
expect(type?.detail).toBeUndefined();
});
}
);
Expand All @@ -35,8 +35,8 @@ describe('type', () => {

const { type } = createFlowPropDef(PROP_NAME, docgenInfo);

expect(type.summary).toBe(x);
expect(type.detail).toBeUndefined();
expect(type?.summary).toBe(x);
expect(type?.detail).toBeUndefined();
});

it(`should support typed ${x}`, () => {
Expand All @@ -54,8 +54,8 @@ describe('type', () => {

const { type } = createFlowPropDef(PROP_NAME, docgenInfo);

expect(type.summary).toBe(`${x}<any>`);
expect(type.detail).toBeUndefined();
expect(type?.summary).toBe(`${x}<any>`);
expect(type?.detail).toBeUndefined();
});
});

Expand Down Expand Up @@ -88,8 +88,8 @@ describe('type', () => {

const { type } = createFlowPropDef(PROP_NAME, docgenInfo);

expect(type.summary).toBe('{ foo: string, bar?: mixed }');
expect(type.detail).toBeUndefined();
expect(type?.summary).toBe('{ foo: string, bar?: mixed }');
expect(type?.detail).toBeUndefined();
});

it('should support long object signature', () => {
Expand Down Expand Up @@ -188,8 +188,8 @@ describe('type', () => {

const { type } = createFlowPropDef(PROP_NAME, docgenInfo);

expect(type.summary).toBe('object');
expect(type.detail).toBe(
expect(type?.summary).toBe('object');
expect(type?.detail).toBe(
'{ (x: string): void, prop1: string, prop2: string, prop3: string, prop4: string, prop5: string, prop6: string, prop7: string, prop8: string }'
);
});
Expand Down Expand Up @@ -218,8 +218,8 @@ describe('type', () => {

const { type } = createFlowPropDef(PROP_NAME, docgenInfo);

expect(type.summary).toBe('(x: string) => void');
expect(type.detail).toBeUndefined();
expect(type?.summary).toBe('(x: string) => void');
expect(type?.detail).toBeUndefined();
});

it('should support tuple', () => {
Expand All @@ -244,7 +244,7 @@ describe('type', () => {

const { type } = createFlowPropDef(PROP_NAME, docgenInfo);

expect(type.summary).toBe('[foo, "value", number]');
expect(type?.summary).toBe('[foo, "value", number]');
});

it('should support union', () => {
Expand All @@ -265,7 +265,7 @@ describe('type', () => {

const { type } = createFlowPropDef(PROP_NAME, docgenInfo);

expect(type.summary).toBe('number | string');
expect(type?.summary).toBe('number | string');
});

it('should support nested union elements', () => {
Expand Down Expand Up @@ -300,7 +300,7 @@ describe('type', () => {

const { type } = createFlowPropDef(PROP_NAME, docgenInfo);

expect(type.summary).toBe('"minimum" | "maximum" | number | string');
expect(type?.summary).toBe('"minimum" | "maximum" | number | string');
});

it('uses raw union value if elements are missing', () => {
Expand All @@ -313,7 +313,7 @@ describe('type', () => {

const { type } = createFlowPropDef(PROP_NAME, docgenInfo);

expect(type.summary).toBe('"minimum" | "maximum" | UserSize');
expect(type?.summary).toBe('"minimum" | "maximum" | UserSize');
});

it('removes a leading | if raw union value is used', () => {
Expand All @@ -326,7 +326,7 @@ describe('type', () => {

const { type } = createFlowPropDef(PROP_NAME, docgenInfo);

expect(type.summary).toBe('"minimum" | "maximum" | UserSize');
expect(type?.summary).toBe('"minimum" | "maximum" | UserSize');
});

it('even removes extra spaces after a leading | if raw union value is used', () => {
Expand All @@ -339,7 +339,7 @@ describe('type', () => {

const { type } = createFlowPropDef(PROP_NAME, docgenInfo);

expect(type.summary).toBe('"minimum" | "maximum" | UserSize');
expect(type?.summary).toBe('"minimum" | "maximum" | UserSize');
});

it('should support intersection', () => {
Expand All @@ -360,6 +360,6 @@ describe('type', () => {

const { type } = createFlowPropDef(PROP_NAME, docgenInfo);

expect(type.summary).toBe('number & string');
expect(type?.summary).toBe('number & string');
});
});

0 comments on commit cb673d8

Please sign in to comment.