Unlike typescript where Record<'foo'|'bar', string> means every key has a value of string, psalm treats this as or.
Currently only array{foo: string, bar: string} is possible to tell psalm that ALL these keys exist with string.
This is a problem for
a) big arrays that have all the same type (e.g. shipping information) where it's hard to read/lots of boilerplate docs
b) does not allow to modify array values but keep the keys the same when using templates, e.g. https://github.com/vimeo/psalm/issues/5994 or https://psalm.dev/r/c39fbb3124
A new map type like map<'foo'|'bar', string> or alternatively (to keep it consistent with typescript) record<'foo'|'bar', string> would resolve this issue.
Since there is already a class-string-map type in psalm, I guess this isn't too far fetched.
Essentially, this new type extends keyed array where all types are identical and all keys are non-optional.
Unlike typescript where Record<'foo'|'bar', string> means every key has a value of string, psalm treats this as
or
. Currently only array{foo: string, bar: string} is possible to tell psalm that ALL these keys exist with string. This is a problem for a) big arrays that have all the same type (e.g. shipping information) where it's hard to read/lots of boilerplate docs b) does not allow to modify array values but keep the keys the same when using templates, e.g. https://github.com/vimeo/psalm/issues/5994 or https://psalm.dev/r/c39fbb3124A new
map
type likemap<'foo'|'bar', string>
or alternatively (to keep it consistent with typescript)record<'foo'|'bar', string>
would resolve this issue.Since there is already a
class-string-map
type in psalm, I guess this isn't too far fetched.Essentially, this new type extends keyed array where all types are identical and all keys are non-optional.
Feedback and suggestions please :-)