Skip to content

Add decoding TypeScript attribute#3054

Merged
rschristian merged 3 commits intopreactjs:masterfrom
sumanthratna:patch-1
Mar 10, 2021
Merged

Add decoding TypeScript attribute#3054
rschristian merged 3 commits intopreactjs:masterfrom
sumanthratna:patch-1

Conversation

@sumanthratna
Copy link
Copy Markdown
Contributor

currently, when I try using:

<img src="..." decoding="async" />

I get this error:

TS2322: Type '{ alt: string; src: string; style: { width: string; height: string; }; className: string; decoding: string; }' is not assignable to type 'HTMLAttributes<HTMLImageElement>'.
  Property 'decoding' does not exist on type 'HTMLAttributes<HTMLImageElement>'.

this patch fixes this issue

@coveralls
Copy link
Copy Markdown

coveralls commented Mar 10, 2021

Coverage Status

Coverage remained the same at 99.445% when pulling 82c827e on sumanthratna:patch-1 into 605bc5e on preactjs:master.

@sumanthratna sumanthratna mentioned this pull request Mar 10, 2021
18 tasks
Copy link
Copy Markdown
Member

@rschristian rschristian left a comment

Choose a reason for hiding this comment

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

If you look at where you added that type, those are all HTML elements. What you did was make <decoding /> a valid HTML element, and it's the type of a HTMLImageElement.

What you'll actually want to do is create a decoding entry under the HTMLAttributes and set it so it matches the attribute's options.

Like this:

decoding?: 'sync' | 'async' | 'auto';

@sumanthratna
Copy link
Copy Markdown
Contributor Author

If you look at where you added that type, those are all HTML elements. What you did was make <decoding /> a valid HTML element, and it's the type of a HTMLImageElement.

What you'll actually want to do is create a decoding entry under the HTMLAttributes and set it so it matches the attribute's options.

Like this:

decoding?: 'sync' | 'async' | 'auto';

whoops, too many types to keep track of :) should be fixed now @rschristian. thanks for taking a look at this PR!

@rschristian rschristian merged commit 9d738ff into preactjs:master Mar 10, 2021
@rschristian
Copy link
Copy Markdown
Member

Thanks!

@sumanthratna sumanthratna deleted the patch-1 branch March 10, 2021 13:40
@sumanthratna
Copy link
Copy Markdown
Contributor Author

@rschristian I know this just got merged but do you have an ETA on the next release?

@rschristian
Copy link
Copy Markdown
Member

I do not, but what you can do is manually add the types until then:

declaration.d.ts

interface HotPatch {
	decoding?: 'sync' | 'async' | 'auto';
}

declare module 'preact' {
	namespace JSX {
		interface IntrinsicAttributes extends HotPatch {}
	}
	interface Attributes extends HotPatch {}
}

Should silence any errors you'd get

This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants