Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React/Typescript not recognizing iframe properties

I am trying to embed an iframe that plays a Vimeo with frameborder and allowfullscreen properties on it with a MyOwnComponent like so:

const MyOwnVimeoComponent = () => {
return (
    <div>
        <iframe 
            src="https://player.vimeo.com/video/VIMEOID" 
            width="640" 
            height="360" 
            frameborder="0" 
            webkitallowfullscreen 
            mozallowfullscreen 
            allowfullscreen
        ></iframe>
    </div>
);}

However, the error I get is:

[ts] Property 'frameborder' does not exist on type 'HTMLProps<HTMLIFrameElement>'

Same for webkitallowfullscreen, mozallowfullscreen and allowfullscreen

After researching other similar problems on StackOverflow it led me to inspect Typescript's lib.d.ts file and look the <HTMLIFrameElement> interface and variable declarations.

The interface does in fact have the properties frameborder and allowfullscreen types on it but it still throws the error. I would understand if it only threw an error for the webkitallowfullscreen and mozallowfullscreen but I am generally confused as to what is happening here.

If anyone can point me in the right direction the would be greatly appreciated.

For reference, here is what seems to be the relevant portion of the lib.d.ts file:

interface HTMLIFrameElement extends HTMLElement, GetSVGDocument {
align: string;
allowFullscreen: boolean;
allowPaymentRequest: boolean;
border: string;
readonly contentDocument: Document;
readonly contentWindow: Window;
frameBorder: string;
frameSpacing: any;
height: string;
hspace: number;
longDesc: string;
marginHeight: string;
marginWidth: string;
name: string;
noResize: boolean;
onload: (this: HTMLIFrameElement, ev: Event) => any;
readonly sandbox: DOMSettableTokenList;
scrolling: string;
src: string;
vspace: number;
width: string;
addEventListener<K extends keyof HTMLIFrameElementEventMap>(type: K, listener: (this: HTMLIFrameElement, ev: HTMLIFrameElementEventMap[K]) => any, useCapture?: boolean): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
}

declare var HTMLIFrameElement: {
    prototype: HTMLIFrameElement;
    new(): HTMLIFrameElement;
}
like image 660
melmquist Avatar asked Jul 12 '17 17:07

melmquist


2 Answers

As you can see in the lib.d.ts file, it should be frameBorder, not frameborder.

Don't worry, it took me a while to spot it too!

like image 125
Tom Fenech Avatar answered Oct 21 '22 22:10

Tom Fenech


See the Following Properties of typed files...

    interface IframeHTMLAttributes<T> extends HTMLAttributes<T> {
        allow?: string;
        allowFullScreen?: boolean;
        allowTransparency?: boolean;
        frameBorder?: number | string;
        height?: number | string;
        marginHeight?: number;
        marginWidth?: number;
        name?: string;
        sandbox?: string;
        scrolling?: string;
        seamless?: boolean;
        src?: string;
        srcDoc?: string;
        width?: number | string;
    }
like image 22
FelipeFerreira Avatar answered Oct 21 '22 21:10

FelipeFerreira