Unverified Commit bb8a49ec authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Omit ignored property from <Image/ > to prevent confusion (#18796)

Fixes #18793
parent 37ed2d23
...@@ -32,7 +32,7 @@ type ImageData = { ...@@ -32,7 +32,7 @@ type ImageData = {
type ImageProps = Omit< type ImageProps = Omit<
JSX.IntrinsicElements['img'], JSX.IntrinsicElements['img'],
'src' | 'srcSet' | 'ref' | 'width' | 'height' | 'loading' 'src' | 'srcSet' | 'ref' | 'width' | 'height' | 'loading' | 'style'
> & { > & {
src: string src: string
quality?: number | string quality?: number | string
......
module.exports = {
images: {
domains: ['via.placeholder.com'],
},
}
import React from 'react'
import Image from 'next/image'
const Invalid = () => {
return (
<div>
<h1>Invalid TS</h1>
<Image
width={500}
height={500}
src="https://via.placeholder.com/500"
style={{ objectFit: 'cover' }}
></Image>
<p id="stubtext">This is the invalid usage</p>
</div>
)
}
export default Invalid
/* eslint-env jest */
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
jest.setTimeout(1000 * 60 * 2)
const appDir = join(__dirname, '..')
describe('TypeScript Image Component with Styles', () => {
describe('next build', () => {
it('should fail to build when the `style` prop is passed to <Image />', async () => {
const { stderr, code } = await nextBuild(appDir, [], { stderr: true })
expect(stderr).toMatch(/Failed to compile/)
expect(stderr).toMatch(/Property 'style' does not exist on type/)
expect(code).toBe(1)
})
})
})
{
"compilerOptions": {
"esModuleInterop": true,
"module": "esnext",
"jsx": "preserve",
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true
},
"exclude": ["node_modules"],
"include": ["next-env.d.ts", "components", "pages"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment