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

fix: tsc error #3362

Merged
merged 6 commits into from
Jul 7, 2024
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
5 changes: 5 additions & 0 deletions .changeset/eight-worms-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/aria-utils": patch
---

Fix tsc error (#2365, #2314, #2505)
2 changes: 1 addition & 1 deletion apps/docs/components/code-window/code-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/components/sonar-pulse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const SonarPulse: FC<SonarPulseProps> = ({
}, [circlesCount, color]);

const renderCircles = useMemo(() => {
const circles = [];
const circles: React.ReactNode[] = [];

for (let i = 1; i < circlesCount; i++) {
circles.push(
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/scripts/update-search-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ const ItemStartContentTemplate = ({color, variant, ...args}: AutocompleteProps<A
);

const ControlledTemplate = ({color, variant, ...args}: AutocompleteProps<Animal>) => {
const [value, setValue] = React.useState<Key>("cat");
const [value, setValue] = React.useState<Key | null>("cat");

const handleSelectionChange = (key: Key) => {
const handleSelectionChange = (key: Key | null) => {
setValue(key);
};

Expand Down
25 changes: 16 additions & 9 deletions packages/components/badge/stories/badge.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,22 @@ const defaultProps = {
content: 5,
};

const Template = (args: BadgeProps) => (
<Badge {...args}>
<Avatar
isBordered={args.classNames?.badge?.includes("bottom")}
radius={args.shape === "rectangle" ? "lg" : "full"}
src="https://i.pravatar.cc/300?u=a042581f4e29026709d"
/>
</Badge>
);
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 (
<Badge {...args}>
<Avatar
isBordered={isBordered}
radius={args.shape === "rectangle" ? "lg" : "full"}
src="https://i.pravatar.cc/300?u=a042581f4e29026709d"
/>
</Badge>
);
};

const ShapesTemplate = (args: BadgeProps) => (
<div className="flex gap-4 items-center">
Expand Down
4 changes: 2 additions & 2 deletions packages/components/calendar/src/calendar-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
27 changes: 14 additions & 13 deletions packages/components/select/__tests__/select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe("Select", () => {
it("should render correctly (dynamic)", () => {
const wrapper = render(
<Select aria-label="Favorite Animal" items={itemsData} label="Favorite Animal">
{(item) => <SelectItem>{item.label}</SelectItem>}
{(item) => <SelectItem key={item.id}>{item.label}</SelectItem>}
</Select>,
);

Expand All @@ -110,7 +110,7 @@ describe("Select", () => {
const wrapper = render(
<Select aria-label="Favorite Animal" items={itemsSectionData} label="Favorite Animal">
{(section) => (
<SelectSection<Item>
<SelectSection<(typeof itemsSectionData)[0]["children"][0]>
aria-label={section.title}
items={section.children}
title={section.title}
Expand Down Expand Up @@ -350,9 +350,9 @@ describe("Select", () => {

it("onSelectionChange should be called with a Set of item ids upon selection", async () => {
const itemsWithId = [
{id: 1, value: "penguin"},
{id: 2, value: "zebra"},
{id: 3, value: "shark"},
{id: "1", value: "penguin"},
{id: "2", value: "zebra"},
{id: "3", value: "shark"},
];

const onSelectionChangeId = jest.fn();
Expand All @@ -363,7 +363,7 @@ describe("Select", () => {
label="Test with ID"
onSelectionChange={onSelectionChangeId}
>
{(item) => <SelectItem>{item.value}</SelectItem>}
{(item) => <SelectItem key={item.id}>{item.value}</SelectItem>}
</Select>,
);

Expand All @@ -390,9 +390,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();
Expand All @@ -403,7 +403,7 @@ describe("Select", () => {
label="Test with Key"
onSelectionChange={onSelectionChangeKey}
>
{(item) => <SelectItem>{item.value}</SelectItem>}
{(item) => <SelectItem key={item.key}>{item.value}</SelectItem>}
</Select>,
);

Expand Down Expand Up @@ -561,6 +561,7 @@ describe("Select", () => {
const formData = new FormData(e.target as HTMLFormElement);

/* eslint-disable no-console */
// @ts-ignore
console.log(JSON.stringify(Object.fromEntries(formData)));
}}
>
Expand Down Expand Up @@ -648,19 +649,19 @@ describe("Select with React Hook Form", () => {
wrapper = render(
<form className="flex flex-col gap-4" onSubmit={handleSubmit(onSubmit)}>
<Select data-testid="select-1" items={itemsData} {...register("withDefaultValue")}>
{(item) => <SelectItem key={item.value}>{item.label}</SelectItem>}
{(item) => <SelectItem key={item.id}>{item.label}</SelectItem>}
</Select>

<Select data-testid="select-2" items={itemsData} {...register("withoutDefaultValue")}>
{(item) => <SelectItem key={item.value}>{item.label}</SelectItem>}
{(item) => <SelectItem key={item.id}>{item.label}</SelectItem>}
</Select>

<Select
data-testid="select-3"
items={itemsData}
{...register("requiredField", {required: true})}
>
{(item) => <SelectItem key={item.value}>{item.label}</SelectItem>}
{(item) => <SelectItem key={item.id}>{item.label}</SelectItem>}
</Select>

{errors.requiredField && <span className="text-danger">This field is required</span>}
Expand Down
2 changes: 1 addition & 1 deletion packages/utilities/aria-utils/src/collections/section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import {HTMLNextUIProps, As} from "@nextui-org/system";
*
*/
export type SectionProps<Type extends As = "div", T extends object = {}> = BaseSectionProps<T> &
winchesHe marked this conversation as resolved.
Show resolved Hide resolved
HTMLNextUIProps<Type>;
Omit<HTMLNextUIProps<Type>, "children">;
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"esModuleInterop": true,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"downlevelIteration": true
"downlevelIteration": true,
"noImplicitAny": false
},
"include": ["packages"],
"exclude": ["**/node_modules", "**/dist", "**/.turbo"]
Expand Down