Skip to content

Commit

Permalink
docs: update nextjs docs for TypeScript support instructions (#946)
Browse files Browse the repository at this point in the history
* Update nextjs docs for TypeScript support instructions

* Add declaration for SVG module with '*.svg?url' import method, from next/image
  • Loading branch information
apetta committed Mar 3, 2024
1 parent 0ae0413 commit 785cba4
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions website/pages/docs/next.mdx
Expand Up @@ -85,3 +85,41 @@ const Example = () => (
```
Please refer to [SVGR webpack guide](/docs/webpack/) for advanced use cases.
## TypeScript
Using SVGR with TypeScript support.
**Type decleration**
Add a custom type decleration file (e.g. **svgr.d.ts**) to the root of your repo.
```ts
declare module '*.svg' {
import { FC, SVGProps } from 'react'
const content: FC<SVGProps<SVGElement>>
export default content
}

declare module '*.svg?url' {
const content: any
export default content
}
```
**tsconfig.json**
Add the type decleration file to your tsconfig.json's `include` array. **Ensure it's the first item.**
```json
{
"include": [
"svgr.d.ts",
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
]
// ...other config
}
```

0 comments on commit 785cba4

Please sign in to comment.