Skip to content

HTMLScriptElement and HTMLStyleElement type definition does not allow to specify "nonce" attribute #24205

Closed
@DethAriel

Description

@DethAriel

According to this MDN page, "nonce" is a valid attribute for a <script> element.
This page says the same about <style> element.

TypeScript Version: 2.9.0-dev.20180516

Search Terms:

Code

declare var scriptElement: HTMLScriptElement;
declare var styleElement: HTMLStyleElement;
scriptElement.nonce = "someValue";
styleElement.nonce = "someValue";

A fully-functional local example can be created like this (verified on MacOS):

mkdir nonce-test
cd nonce-test/
yarn init -p -y
yarn add typescript@next

touch test.ts
echo 'declare var scriptElement: HTMLScriptElement;' >> test.ts
echo 'declare var styleElement: HTMLStyleElement;' >> test.ts
echo 'scriptElement.nonce = "someValue";' >> test.ts
echo 'styleElement.nonce = "someValue";' >> test.ts

yarn tsc test.ts --target ES6 --noEmit 

Expected behavior:

the command

tsc test.ts --target ES6 --noEmit 

should complete without errors

Actual behavior:

There are two errors reported:

test.ts:3:15 - error TS2339: Property 'nonce' does not exist on type 'HTMLScriptElement'.

3 scriptElement.nonce = "someValue";
                ~~~~~


test.ts:4:14 - error TS2339: Property 'nonce' does not exist on type 'HTMLStyleElement'.

4 styleElement.nonce = "someValue";
               ~~~~~


Playground Link:
http://www.typescriptlang.org/play/index.html#src=declare%20var%20scriptElement%3A%20HTMLScriptElement%3B%0D%0Adeclare%20var%20styleElement%3A%20HTMLStyleElement%3B%0D%0AscriptElement.nonce%20%3D%20%22someValue%22%3B%0D%0AstyleElement.nonce%20%3D%20%22someValue%22%3B

Related Issues:

Although issue #8955 and pr #8956 are not related to this particular issue, they deal with a very similar problem of having incomplete typings

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions