字符串在ts中不可变,无法就地更改字符串值

36 阅读1分钟

字符串在ts中不可变,无法就地更改字符串值

测试代码:

    let a: string = '12345'
    a[2] = 'a'
    console.log(a)

报错:

error TS2542: Index signature in type 'String' only permits reading.