Skip to content

Map does not have a type-checked "get" method #37392

Open
@jamesderlin

Description

@jamesderlin

This is the same request as #36541 but for a slightly different reason: I'd like a version of Map.operator [] that type-checks the key.

As I mentioned in #57844:

I recently found a bug where I accidentally typed someMap[someObject] instead of someMap[someObject.id]. (operator []= does use the Map's key type but operator [] uses Object.)

Arguably this wouldn't be necessary with #57844, although conceivably one might want strict type-checking without relying on lints being configured. It's also unclear what the timeline might be for implementing that.

(Alternatively, operator [] (and various other functions) could take the key type. I know that the rationale is that asking a collection of K if it contains something else isn't wrong, but it's not clear to me when it's actually the right thing to do. That is, in what circumstances is that desirable? I've seen some academic examples with questionable real-world utility, whereas the lack of typing is known to cause bugs in real code.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.enhancement-breaking-changeAn enhancement which is breaking.library-coretype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions