#Why is TS giving an error on this?

1 messages · Page 1 of 1 (latest)

nova stratusBOT
#
hornta#4659

Preview:```ts
const structures = {
foo: {
propOfFoo: "",
},
bar: {
propOfBar: "",
},
}

const getStructure = (id: keyof typeof structures) => {
return structures[id]
}

const structure = getStructure("foo")
structure.foo```

spark dawn
#

@quiet briar Because getStructure's type is: (id: "foo" | "bar") => { propOfFoo: string } | { propOfBar: string }. The inferred signature does not specifically match "foo" input to structures.foo output.