microsoft / microsoft/TypeScript
function members of primitives/builtins are not read-only
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
🔎 Search Terms
builtin number string member readonly
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about "Common Bugs that arent Bugs"
⏯ Playground Link
💻 Code
let x = 2;
x.valueOf = (2).valueOf;
let y = "hello";
y.charAt = y.charAt;
🙁 Actual behavior
Code compiles just fine, even with --strict enabled.
Executing JavaScript fails:
can't assign to property "valueOf" on 2: not an object
🙂 Expected behavior
Should be rejected by tsc as read-only assignment.
Additional information about the issue
Seems similar in nature to https://github.com/microsoft/TypeScript/issues/49113
Notably, array.length is allowed (because its legal in JS) but string.length is not (because it is illegal in JS). Since assigning to builtin functions is also illegal, this should be flagged by tsc.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked TypeScript Playground example and reproduce the assignments under --strict with tsc. Trace how assignments to primitive members are checked, then add rejection for illegal writes to builtin functions while preserving legal JavaScript cases such as array.length; add or update compiler tests to cover the examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100