Skip to content

new Map(Iterable[K, V]) with complex value type V can have arbitrary extra properties on each VΒ #49500

Closed
@thisisrandy

Description

@thisisrandy

Bug Report

πŸ”Ž Search Terms

map from iterable

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "map". The issue exhibits on the nightly playground.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

interface Foo {
  bar: string,
  baz: number
}

// no error, even though qux is not a valid property of Foo
let fooMap: Map<string, Foo> = new Map([["foo", {bar: "bar", baz: 1, qux: "qux"}]]);
// the subtractive case is caught
fooMap = new Map([["foo", {bar: "bar", qux: "qux"}]]);
// if the iterable is pulled out and typed, the error is caught. could
// also achieve this with a suffix of `as [string, Foo][]` above
let fooIterable: [string, Foo][] = [["foo", {bar: "bar", baz: 1, qux: "qux"}]]
// setting with invalid values is also caught
fooMap.set("bar", {bar: "bar", baz: 1, qux: "qux"})
// it's worth noting that primitive value types are checked as expected
let stringMap: Map<string, string> = new Map([["foo", 1]])

πŸ™ Actual behavior

identifier: Map<K, V> = new Map(Iterable[K, V]) allows each V in the iterable to have arbitrary extra properties.

πŸ™‚ Expected behavior

identifier: Map<K, V> = new Map(Iterable[K, V]) should check that each value in the iterable is a valid V.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions