TypeScript example not working
See original GitHub issueI modified the TypeScript example a little bit like this:
import { withOGImage, NextApiOgImageConfig } from 'next-api-og-image'
interface IHTML {
heading: NextApiOgImageConfig<'heading'>
}
const html = async ({ heading }: IHTML) => {
return `
<html>
<head>
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>
<h1>${heading}</h1>
</body>
</html>
`
}
const nextApiOgImageConfig = {
// 'Content-Type' HTTP header
contentType: 'image/png',
// 'Cache-Control' HTTP header
cacheControl: 'max-age 3600, must-revalidate',
// NOTE: Options within 'dev' object works only when process.env.NODE_ENV === 'development'
dev: {
// Whether to replace binary data (image/screenshot) with HTML
// that can be debugged in Developer Tools
inspectHtml: true,
},
html,
}
export default withOGImage<'heading'>(nextApiOgImageConfig)
And it’s not working. I get an error on the last line on nextApiOgImageConfig
saying:
Argument of type '{ contentType: string; cacheControl: string; dev: { inspectHtml: boolean; }; html: ({ heading }: IHTML) => Promise<string>; }' is not assignable to parameter of type 'NextApiOgImageConfig<"heading">'.
Types of property 'html' are incompatible.
Type '({ heading }: IHTML) => Promise<string>' is not assignable to type '(...queryParams: Record<"heading", string | string[]>[]) => string | Promise<string>'.
Types of parameters '__0' and 'queryParams' are incompatible.
Type 'Record<"heading", string | string[]>' is not assignable to type 'IHTML'.
Types of property 'heading' are incompatible.
Type 'string | string[]' is not assignable to type 'NextApiOgImageConfig<"heading">'.
Type 'string' is not assignable to type 'NextApiOgImageConfig<"heading">'.ts(2345)
How do I fix that?
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Common TypeScript module problems and how to solve them
A firm understanding of TypeScript modules system. Problem 1: Irregular location of dependencies. On a normal occasion, the node-modules ...
Read more >JavaScript code inside TypeScript file .ts not working
I am working on a web project with Visual Studio and TypeScript plugin. Inside the following post, I have found this answer: Not...
Read more >TypeScript - watch-example - not working · Issue #401 - GitHub
I copy-pasted the example, and exported a module, here goes: const k8s = require('@kubernetes/client-node'); const kc = new k8s.
Read more >Troubleshooting Handbook: Types
Facing weird type errors? You aren't alone. This is the hardest part of using TypeScript with React. Be patient - you are learning...
Read more >How to set up TypeScript
Having TypeScript set up on a per-project basis lets you have many projects with many different versions of TypeScript, this keeps each project...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey @deadcoder0904, Please see https://github.com/neg4n/next-api-og-image#splitting-files for example usage of query params helper type 😄 I’m closing the issue - I think everything has been said. If I’m mistaken, feel free to reopen it! 🤗 Cheers
Simplified it a bit: