Skip to content
webtype.orgwebtype.orgtsconfig

    ↑↓ move · ⏎ open · esc close

    tsconfig

    noPropertyAccessFromIndexSignature

    Dotted access means declared

    Reserves `obj.key` for properties that were actually declared, and pushes everything from an index signature to `obj["key"]`.

    Since
    TypeScript 4.2
    strict
    Not in strict
    In your tsconfig
    "noPropertyAccessFromIndexSignature": true

    The same snippet both times. Only the option changed.

    With it off

    "noPropertyAccessFromIndexSignature": false
    const env: { [key: string]: string } = {}
    
    export const mode = env.NODE_ENV

    Compiles clean

    With it on

    "noPropertyAccessFromIndexSignature": true
    const env: { [key: string]: string } = {}
    
    export const mode = env.NODE_ENV

    Emits TS4111

    Why the compiler bothers

    It is a notation rule rather than a soundness one, and it earns its place because of what a reader can then infer: with it on, a dot means somebody wrote that property down, and a bracket means the key is data. Without it, `env.NODE_ENV` and `config.timeout` look identical and only one of them is checked against anything. It pairs naturally with `noUncheckedIndexedAccess`, which supplies the other half — that the value might not be there at all.

    Takeaway

    Dot for what the type declares, bracket for what the data happens to hold.

    Where to go next

    22 options