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

ElementCSSInlineStyle.style should not be read-only #38838

Open
pygy opened this issue May 29, 2020 · 1 comment
Open

ElementCSSInlineStyle.style should not be read-only #38838

pygy opened this issue May 29, 2020 · 1 comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript
Milestone

Comments

@pygy
Copy link

pygy commented May 29, 2020

TypeScript Version: Nightly

Search Terms:

DOM Element HTMLElement SVGElement inline style setter

Expected behavior:

Per https://drafts.csswg.org/cssom/#elementcssinlinestyle, the style setter is forwarded to style.cssText, and thus accepts a string.

Actual behavior:

Type error:

(property) ElementCSSInlineStyle.style: CSSStyleDeclaration
Cannot assign to 'style' because it is a read-only property.(2540)

Related Issues:

#13466, which (correctly) points to the old spec where ElementCSSInlineStyle.style was only described as readonly, without the PutForwards=cssText annotation.

This is however a case of an old spec that doesn't match a universal browser behavior.

w3c/csswg-drafts#5127 where I asked the W3C for clarification

Code

const a = document.createElement("a")

a.style = ""
Output
"use strict";
const a = document.createElement("a");
a.style = "";
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "useDefineForClassFields": false,
    "alwaysStrict": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "downlevelIteration": false,
    "noEmitHelpers": false,
    "noLib": false,
    "noStrictGenericChecks": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "esModuleInterop": true,
    "preserveConstEnums": false,
    "removeComments": false,
    "skipLibCheck": false,
    "checkJs": false,
    "allowJs": false,
    "declaration": true,
    "experimentalDecorators": false,
    "emitDecoratorMetadata": false,
    "target": "ES2017",
    "module": "ESNext"
  }
}

Playground Link: Provided

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jun 11, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jun 11, 2020
@RyanCavanaugh RyanCavanaugh added the Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript label Jun 11, 2020
@byterider
Copy link

I wonder why even MDN says "Styles should not be set by assigning a string directly to the style property (as in elt.style = "color: blue;"), since it is considered read-only, as the style attribute returns a CSSStyleDeclaration object which is also read-only."
https://developer.mozilla.org/en-US/docs/Web/API/ElementCSSInlineStyle/style

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants