AArtem UdovichenkoAdd ets2panda
0ee26c4f创建于 2023年10月10日历史提交

as const assertions are not supported

Rule arkts-no-as-const

Severity: error

ArkTS does not support as const assertions because in the standard TypeScript as const annotates literals with corresponding literal types, and ArkTS does not support literal types.

TypeScript


    // Type 'hello':
    let x = "hello" as const

    // Type 'readonly [10, 20]':
    let y = [10, 20] as const

    // Type '{ readonly text: "hello" }':
    let z = { text: "hello" } as const

ArkTS


    // Type 'string':
    let x : string = "hello"

    // Type 'number[]':
    let y : number[] = [10, 20]

    class Label {
        text : string = ""
    }

    // Type 'Label':
    let z : Label = {
        text: "hello"
    }