Microsoft/TypeScript

`.length` property of function literals is not `readonly`

Open

#49.113 geöffnet am 14. Mai 2022

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
BugDomain: lib.d.tsHelp Wanted

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

Bug Report

Function .length property is inconsistently readonly depending on whether Function constructor is used or not.

🔎 Search Terms

function length readonly

🕗 Version & Regression Information

v4.6.2 (haven't checked older versions)

⏯ Playground Link

Playground link with relevant code

💻 Code

const f = new Function()
f.length = 1 // Error here: Cannot assign to 'length' because it is a read-only property.

const f2 = () => {}
f2.length = 1 // No error here

🙁 Actual behavior

The length property of the function created with new Function() is readonly while the length property of function literals is not.

🙂 Expected behavior

Both length properties should be readonly. Alternative both could be non-readonly but that seems worse since JS doesn't modify the length when assigning a value.

Contributor Guide