From 60bb09fe6455475a16225e776348e9acf0537f9b Mon Sep 17 00:00:00 2001 From: winches <329487092@qq.com> Date: Sun, 7 Jul 2024 12:19:09 +0800 Subject: [PATCH] fix: tsc errors (#3362) * fix: tsc error * docs: changeset * fix: test * fix: test * fix: review problem * fix: review --- .changeset/eight-worms-cough.md | 5 ++++ .../components/code-window/code-block.tsx | 2 +- apps/docs/components/sonar-pulse.tsx | 2 +- apps/docs/scripts/update-search-meta.ts | 4 +-- .../stories/autocomplete.stories.tsx | 4 +-- .../badge/stories/badge.stories.tsx | 25 ++++++++++------- .../components/calendar/src/calendar-base.tsx | 4 +-- .../select/__tests__/select.test.tsx | 27 ++++++++++--------- .../aria-utils/src/collections/section.ts | 2 +- tsconfig.json | 3 ++- 10 files changed, 46 insertions(+), 32 deletions(-) create mode 100644 .changeset/eight-worms-cough.md diff --git a/.changeset/eight-worms-cough.md b/.changeset/eight-worms-cough.md new file mode 100644 index 0000000000..a2ad48a744 --- /dev/null +++ b/.changeset/eight-worms-cough.md @@ -0,0 +1,5 @@ +--- +"@nextui-org/aria-utils": patch +--- + +Fix tsc error (#2365, #2314, #2505) diff --git a/apps/docs/components/code-window/code-block.tsx b/apps/docs/components/code-window/code-block.tsx index 74de828f20..a5bf43cbee 100644 --- a/apps/docs/components/code-window/code-block.tsx +++ b/apps/docs/components/code-window/code-block.tsx @@ -39,7 +39,7 @@ export type CodeBlockProps = PreProps & { * recursively get all text nodes as an array for a given element */ function getTextNodes(node: any): any[] { - let childTextNodes = []; + let childTextNodes: React.ReactNode[] = []; if (!node.hasChildNodes()) return []; diff --git a/apps/docs/components/sonar-pulse.tsx b/apps/docs/components/sonar-pulse.tsx index 0176d26e85..5bfc177d25 100644 --- a/apps/docs/components/sonar-pulse.tsx +++ b/apps/docs/components/sonar-pulse.tsx @@ -41,7 +41,7 @@ export const SonarPulse: FC = ({ }, [circlesCount, color]); const renderCircles = useMemo(() => { - const circles = []; + const circles: React.ReactNode[] = []; for (let i = 1; i < circlesCount; i++) { circles.push( diff --git a/apps/docs/scripts/update-search-meta.ts b/apps/docs/scripts/update-search-meta.ts index 192c862f62..74c70c2c36 100644 --- a/apps/docs/scripts/update-search-meta.ts +++ b/apps/docs/scripts/update-search-meta.ts @@ -54,7 +54,7 @@ async function getMDXMeta(file: string) { const result:ResultType[] = []; - const title = !!frontMatter.title ? frontMatter.title : ""; + const title = frontMatter.title || ""; result.push({ content: title, @@ -96,7 +96,7 @@ async function getSearchMeta(saveMode: "algolia" | "local" = "local") { .filter((file: any) => file.endsWith(".mdx")); for (const file of files) { - let result = []; + let result: ResultType[] = []; try { result = await getMDXMeta(file); diff --git a/packages/components/autocomplete/stories/autocomplete.stories.tsx b/packages/components/autocomplete/stories/autocomplete.stories.tsx index 022e249e6c..e5758cf07e 100644 --- a/packages/components/autocomplete/stories/autocomplete.stories.tsx +++ b/packages/components/autocomplete/stories/autocomplete.stories.tsx @@ -431,9 +431,9 @@ const ItemStartContentTemplate = ({color, variant, ...args}: AutocompleteProps) => { - const [value, setValue] = React.useState("cat"); + const [value, setValue] = React.useState("cat"); - const handleSelectionChange = (key: Key) => { + const handleSelectionChange = (key: Key | null) => { setValue(key); }; diff --git a/packages/components/badge/stories/badge.stories.tsx b/packages/components/badge/stories/badge.stories.tsx index 6ec76fb076..489654e07c 100644 --- a/packages/components/badge/stories/badge.stories.tsx +++ b/packages/components/badge/stories/badge.stories.tsx @@ -65,15 +65,22 @@ const defaultProps = { content: 5, }; -const Template = (args: BadgeProps) => ( - - - -); +const Template = (args: BadgeProps) => { + const classNamesBadge = args.classNames?.badge; + const isBordered = Array.isArray(classNamesBadge) + ? classNamesBadge?.some((c) => (c as string).includes("bottom")) + : (classNamesBadge as string)?.includes("bottom"); + + return ( + + + + ); +}; const ShapesTemplate = (args: BadgeProps) => (
diff --git a/packages/components/calendar/src/calendar-base.tsx b/packages/components/calendar/src/calendar-base.tsx index 0d5def77b1..af6d34ff80 100644 --- a/packages/components/calendar/src/calendar-base.tsx +++ b/packages/components/calendar/src/calendar-base.tsx @@ -59,8 +59,8 @@ export function CalendarBase(props: CalendarBaseProps) { const currentMonth = state.visibleRange.start; - const headers = []; - const calendars = []; + const headers: React.ReactNode[] = []; + const calendars: React.ReactNode[] = []; for (let i = 0; i < visibleMonths; i++) { let d = currentMonth.add({months: i}); diff --git a/packages/components/select/__tests__/select.test.tsx b/packages/components/select/__tests__/select.test.tsx index 3f603051e3..61a9e753a8 100644 --- a/packages/components/select/__tests__/select.test.tsx +++ b/packages/components/select/__tests__/select.test.tsx @@ -85,7 +85,7 @@ describe("Select", () => { it("should render correctly (dynamic)", () => { const wrapper = render( , ); @@ -112,7 +112,7 @@ describe("Select", () => { const wrapper = render( , ); @@ -392,9 +392,9 @@ describe("Select", () => { it("onSelectionChange should be called with a Set of item keys upon selection", async () => { const itemsWithKey = [ - {key: 1, value: "penguin"}, - {key: 2, value: "zebra"}, - {key: 3, value: "shark"}, + {key: "1", value: "penguin"}, + {key: "2", value: "zebra"}, + {key: "3", value: "shark"}, ]; const onSelectionChangeKey = jest.fn(); @@ -405,7 +405,7 @@ describe("Select", () => { label="Test with Key" onSelectionChange={onSelectionChangeKey} > - {(item) => {item.value}} + {(item) => {item.value}} , ); @@ -563,6 +563,7 @@ describe("Select", () => { const formData = new FormData(e.target as HTMLFormElement); /* eslint-disable no-console */ + // @ts-ignore console.log(JSON.stringify(Object.fromEntries(formData))); }} > @@ -683,11 +684,11 @@ describe("Select with React Hook Form", () => { wrapper = render(
{errors.requiredField && This field is required} diff --git a/packages/utilities/aria-utils/src/collections/section.ts b/packages/utilities/aria-utils/src/collections/section.ts index ae5f84eae5..949092c64e 100644 --- a/packages/utilities/aria-utils/src/collections/section.ts +++ b/packages/utilities/aria-utils/src/collections/section.ts @@ -7,4 +7,4 @@ import {HTMLNextUIProps, As} from "@nextui-org/system"; * */ export type SectionProps = BaseSectionProps & - HTMLNextUIProps; + Omit, "children">; diff --git a/tsconfig.json b/tsconfig.json index 4dba2cb1fe..d9d59f63cf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,7 +15,8 @@ "esModuleInterop": true, "resolveJsonModule": true, "allowSyntheticDefaultImports": true, - "downlevelIteration": true + "downlevelIteration": true, + "noImplicitAny": false }, "include": ["packages"], "exclude": ["**/node_modules", "**/dist", "**/.turbo"]