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 decoding TypeScript attribute #3054

Merged
merged 3 commits into from
Mar 10, 2021
Merged

Conversation

sumanthratna
Copy link
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

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
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
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
Member

Thanks!

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

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

@rschristian
Copy link
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