Typescript: Poll: Name a compiler option for including `undefined` when a property resolves to an index signature

Created on 8 Sep 2020  路  19Comments  路  Source: microsoft/TypeScript

We need a name for the option described in #13778

The exact behavior that this flag would enable is, briefly:

  • Read expressions of the form expr[i] will now be T | undefined where T is the index signature type
  • Read expressions of the form expr.prop will now be T | undefined where T is the index signature type if an index signature on expr exists but not a declared property named prop
  • string and number index signatures are both subjected to this treatment
  • Write expressions expr[i] = v and expr.prop = v are unaffected
  • Type expressions TypeName[number] and TypeName["prop"] are unaffected

Good candidate flag names should follow these rules and goals:

  • Do not start with strict since this flag would not get turned on by the global --strict setting
  • Follow an existing convention (see the list at (https://aka.ms/tsconfig.json)
  • Convey the intent of the flag along with its behavior, somehow
  • Avoid problematic terms (e.g. do not reference mental illnesses)

This is an open-ended approval voting issue. Rules:

  • Use 馃憤 reaction on as many as you like

    • Top-upvoted options will be given the most consideration

    • This is an advisory vote; final say is still up to the TypeScript team

  • You may propose new options; comments must be of exactly the form `--proposedOptionName`

    • Follow the above guidance - no --strictFoo!

  • No discussion here; discuss in #13778. Non-option comments will be deleted
  • Sharing this link on social media is encouraged!

I will seed this with some of the names suggested at our last meeting. We may also cull options that aren't receiving a lot of votes to help keep the comment count manageable.

Add a Flag Meta-Issue help wanted

Most helpful comment

--noUncheckedIndexedAccess

All 19 comments

--pedanticIndexSignatures

--noUncheckedIndexedAccess

--undefinedIndexSignatures

--skepticalIndexAccesses

--noImplicitBounds

--rigorousIndexAccess

--carefulIndexAccess

--partialIndexedAccess

--maybeIndexAccess

--indexNullChecks (like --strictNullChecks but for index access)

--safeIndexAccess

--soundIndexedAccess

--uncertainIndexAccess

Personally I feel the name should highlight the aspect of uncertainty introduced here, rather than the aspect of strictness.

--includeUndefinedInIndexSignatures

--includeUndefinedInIndexAccess

--noUncheckedIndexedAccess

I think this one nails it, however I'd adjust it to --noUncheckedIndexAccess (uncheck-ed and index-ed it a feels a bit too much of -ed).

--checkIndexedAccess

We have a winner 馃

Are you rolling with --noUncheckedIndexedAccess or @alex-okrushko's suggested tweak of --noUncheckedIndexAccess?

Was this page helpful?
0 / 5 - 0 ratings