Skip to content

element.style[key] = value throws implicit any error #11914

Closed
@appsforartists

Description

@appsforartists

TypeScript Version: 2.0.3

Code

const propName: string = 'position';

const div = document.getElementsByTagName('div')[0];
div.style[propName] = 'absolute';

Expected behavior:
Styles are dynamically settable with dictionary access; the above snippet should set position: absolute on div

Actual behavior:
Throws

ERROR(4,1): : Element implicitly has an 'any' type because index expression is not of type 'number'.

Must use format style.setProperty(key, value);

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions