Skip to content
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

Use unknown instead of any for better type safety #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/renderers/contentful-fields-only/fields/renderLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { renderUnionValues } from "../../typescript/renderUnion"

export default function renderLink(field: Field): string {
if (field.linkType === "Asset") {
return "any"
return "unknown"
}

if (field.linkType === "Entry") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Field } from "contentful"

export default function renderRichText(field: Field): string {
return "any"
return "unknown"
}
2 changes: 1 addition & 1 deletion src/renderers/contentful-fields-only/renderContentType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function renderContentType(contentType: ContentType): string {
name,
fields: `
fields: { ${fields} };
[otherKeys: string]: any;
[otherKeys: string]: unknown;
`,
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/contentful/fields/renderObject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Field } from "contentful"

export default function renderObject(field: Field): string {
return "Record<string, any>"
return "Record<string, unknown>"
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("renderLink()", () => {
omitted: false,
}

expect(renderLink(assetLink)).toMatchInlineSnapshot(`"any"`)
expect(renderLink(assetLink)).toMatchInlineSnapshot(`"unknown"`)
})

it("handles mysteries", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ describe("renderRichText()", () => {
}

it("works", () => {
expect(renderRichText(simpleRichText).trim()).toMatchInlineSnapshot(`"any"`)
expect(renderRichText(simpleRichText).trim()).toMatchInlineSnapshot(`"unknown"`)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("renderContentType()", () => {
/** Array field */
arrayField: (\\"one\\" | \\"of\\" | \\"the\\" | \\"above\\")[]
};
[otherKeys: string]: any;
[otherKeys: string]: unknown;
}"
`)
})
Expand Down
2 changes: 1 addition & 1 deletion test/renderers/contentful/fields/renderObject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ describe("renderObject()", () => {
}

it("works", () => {
expect(renderObject(simpleObject).trim()).toMatchInlineSnapshot(`"Record<string, any>"`)
expect(renderObject(simpleObject).trim()).toMatchInlineSnapshot(`"Record<string, unknown>"`)
})
})
4 changes: 2 additions & 2 deletions test/renderers/renderFieldsOnly.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("renderFieldsOnly()", () => {
/** Array field */
arrayField: (\\"one\\" | \\"of\\" | \\"the\\" | \\"above\\")[]
}
[otherKeys: string]: any
[otherKeys: string]: unknown
}
"
`)
Expand All @@ -55,7 +55,7 @@ describe("renderFieldsOnly()", () => {
/** Array field */
arrayField: (\\"one\\" | \\"of\\" | \\"the\\" | \\"above\\")[]
}
[otherKeys: string]: any
[otherKeys: string]: unknown
}
}

Expand Down