Skip to content

String indexer is readonly in lib._x_.d.ts #10097

Closed
@david-driscoll

Description

@david-driscoll

Currently the string indexer is currently set to readonly in lib.d.ts. When trying to swap out characters in a string, you must cast to any to solve. Is this expected behavior, or a side effect of some other issue being solved?

This is not an issue for Array, as it's indexer is mutable.

https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es5.d.ts#L442
https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es6.d.ts#L442
https://github.com/Microsoft/TypeScript/blob/master/lib/lib.d.ts#L442

TypeScript Version: 1.8.0 / nightly (2.0.0-dev.201xxxxx)
2.1.0-dev.20160801
Code

let rangeValue = '1234567890123'
if (rangeValue.length > 1) {
    rangeValue[0] = 'V';
}  

Expected behavior:
Should be able to assign a value to any index of a string;

Actual behavior:
Get compiler error Left-hand side of assignment expression cannot be a constant or a read-only property.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExternalRelates to another program, environment, or user action which we cannot control.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions