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

Add possible to override type of '*.svg' #30060

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions packages/next/image-types/global.d.ts
Expand Up @@ -16,11 +16,30 @@ declare module '*.png' {

declare module '*.svg' {
/**
* Use `any` to avoid conflicts with
* By default, use `any` to avoid conflicts with
* `@svgr/webpack` plugin or
* `babel-plugin-inline-react-svg` plugin.
*
* If you are not using these plugins, you can override
* the default behavior using a code snippet inside your project
*
* // yourProject/src/global.d.ts
Copy link
Member

@styfle styfle Oct 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We document this as additional.d.ts and it needs to be added to the include array

image

https://nextjs.org/docs/basic-features/typescript

* declare module '*.svg' {
* export interface OverrideDefaultTypeSettings {
* useAny: false;
* }
* }
*/
Copy link
Member

@styfle styfle Oct 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we modify the type when we detect the svg loaders so the user doesn't need to do anything?

For example, see #26281

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to figure out how this can be done

const content: any
interface DefaultTypeSettings {
useAny: true;
}

export interface OverrideDefaultTypeSettings {}

type TypeSettings = Omit<DefaultTypeSettings, keyof OverrideDefaultTypeSettings> & OverrideDefaultTypeSettings;
type ContentType = TypeSettings['useAny'] extends true ? any : StaticImageData;

const content: ContentType;

export default content
}
Expand Down