At the moment, (where food is equal to the README example)
const oatyFood = new OatyArray(food, { keys: ['id', 'type'] })
const idOne = oatyFood.get("fruit", 1)
idOne has the following type:
const idOne: {
id: number;
name: string;
type: string;
}[] | undefined
which is annoying for two reasons:
- Need code to check if
idOne is defined
- Need to check array length is
1
That second reason is particularly annoying if you know that id is unique the source data.
Would be cool if oaty supported something like:
const oatyFood = new OatyArray(food, {
keys: [
{ key: "id", unique: true },
{ key: "type" }
],
});
and could even make this backwards-compatible, e.g.
const oatyFood = new OatyArray(food, {
keys: [{ key: "id", unique: true }, "type"],
});
and then the type for oatyFood.get("id", 1) should become
const idOne: {
id: number;
name: string;
type: string;
} | undefined
which still requires a (necessary and not that annoying) check for undefined, but means you don't need to check the array (not necessary and very annoying)
At the moment, (where
foodis equal to the README example)idOnehas the following type:which is annoying for two reasons:
idOneis defined1That second reason is particularly annoying if you know that
idis unique the source data.Would be cool if oaty supported something like:
and could even make this backwards-compatible, e.g.
and then the type for
oatyFood.get("id", 1)should becomewhich still requires a (necessary and not that annoying) check for
undefined, but means you don't need to check the array (not necessary and very annoying)