key: string
?const posts: Posts = blogPosts
const data: Post = posts[props.name]
const result: Post = blogPosts[props.name]
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ 'story': { header: string; page: { tag: string; image_src: string; image_alt: string; }[]; }; }'.
No index signature with a parameter of type 'string' was found on type '{ 'story': { header: string; page: { tag: string; image_src: string; image_alt: string; }[]; }; }'
const result: Post = blogPosts[props.name]
в этом решении, почему тут Post не прокатил export type Params<Key extends string = string> = {
readonly [key in Key]: string | undefined;
};
export function getContact(params: {id: string}): Promise<IContact> {
const getTimeout = () => Math.floor(Math.random() * 1000)
return new Promise((resolve) => {
setTimeout(() => {
resolve(createRandomContact(params.id))
}, getTimeout())
})
}
export const loader:LoaderFunction = async ({params}: {params: Params}) => {
const contact = await getContact(params)
return contact
}
Argument of type 'Params' is not assignable to parameter of type '{ id: string; }'.
Property 'id' is missing in type 'Params' but required in type '{ id: string; }'.