How to fix Binding element implicitly has an 'any' type.
Answered
Yellowstripe scad posted this in #help-forum
Yellowstripe scadOP
page.tsx -
SwitchCard.tsx -
data parameter is giving the error in SwitchCard.tsx
in this case, data is an object, json.
import Head from 'next/head';
import { useRouter } from 'next/router';
import switchesData from "@/public/keyboardSwitches.json"
import Image from 'next/image'
import SwitchCard from '@/components/SwitchCard';
export default async function Home() {
console.log(switchesData)
return (
<div className="px-0 py-4 xl:py-10 lg:py-7 lg:px-26 xl:px-40 w-full h-full">
<div className="w-100 rounded-lg h-20 bg-gray-100 p-3 flex flex-row items-center justify-center">
search/filters box
</div>
<div className="rounded-lg py-3 grid grid-cols-2 gap-2 lg:grid-cols-4">
{switchesData.map((switchItem) => (
<SwitchCard key={switchItem.id} data={switchItem} />
))}
</div>
</div>
)
}SwitchCard.tsx -
"use client"
import Image from "next/image";
import { Button } from "./ui/button";
import Link from "next/link";
import switchData from "@/public/keyboardSwitches.json"
import EmblaCarousel from "./embla/EmblaCarousel";
export default function SwitchCard({ data }) {
console.log(data)
return <p>hello</p>
}data parameter is giving the error in SwitchCard.tsx
in this case, data is an object, json.
Answered by Ray
I'm not sure what is inside switchData but you can try something like this
import switchesData from "@/public/keyboardSwitches.json"
export default function SwitchCard({ data }:{ data: typeof switchesData[0] }) {
console.log(data)
return <p>hello</p>
}5 Replies
@Ray create the typescript type for it
Yellowstripe scadOP
im new to nextjs and typescript, how would I do that. is there somewhere that lists all types
@Yellowstripe scad page.tsx - js
import Head from 'next/head';
import { useRouter } from 'next/router';
import switchesData from "@/public/keyboardSwitches.json"
import Image from 'next/image'
import SwitchCard from '@/components/SwitchCard';
export default async function Home() {
console.log(switchesData)
return (
<div className="px-0 py-4 xl:py-10 lg:py-7 lg:px-26 xl:px-40 w-full h-full">
<div className="w-100 rounded-lg h-20 bg-gray-100 p-3 flex flex-row items-center justify-center">
search/filters box
</div>
<div className="rounded-lg py-3 grid grid-cols-2 gap-2 lg:grid-cols-4">
{switchesData.map((switchItem) => (
<SwitchCard key={switchItem.id} data={switchItem} />
))}
</div>
</div>
)
}
SwitchCard.tsx - js
"use client"
import Image from "next/image";
import { Button } from "./ui/button";
import Link from "next/link";
import switchData from "@/public/keyboardSwitches.json"
import EmblaCarousel from "./embla/EmblaCarousel";
export default function SwitchCard({ data }) {
console.log(data)
return <p>hello</p>
}
data parameter is giving the error in SwitchCard.tsx
in this case, data is an object, json.
I'm not sure what is inside switchData but you can try something like this
import switchesData from "@/public/keyboardSwitches.json"
export default function SwitchCard({ data }:{ data: typeof switchesData[0] }) {
console.log(data)
return <p>hello</p>
}Answer
@Ray I'm not sure what is inside switchData but you can try something like this
ts
import switchesData from "@/public/keyboardSwitches.json"
export default function SwitchCard({ data }:{ data: typeof switchesData[0] }) {
console.log(data)
return <p>hello</p>
}
Yellowstripe scadOP
this works! thank you
@Yellowstripe scad this works! thank you
cool, please mark solution