Closed
Description
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
Labels
No labels