#What does [K in T & string]?

9 messages · Page 1 of 1 (latest)

uneven sandal
#

I don't quite understand what precisely the & string addition makes and what use cases are. Could you please clarify?

type DescribeObject<T> = {
  [K in keyof T]: { value: T[K] } & DescribeWhat<T[K]>;
};

vs

type DescribeObject<T> = {
  [K in keyof T & string]: { value: T[K] } & DescribeWhat<T[K]>;
};
#

Is it the same as [K in NonNullable<keyof T>] ?

frank lotus
#

It's just X & string.

uneven sandal
#

And what it does?

#

so it can't be number for example, right?

oak walrusBOT
#
type X = 'foo' | 'bar' | 42 | symbol | true
type Result = X & string
//   ^? - type Result = "foo" | "bar"
frank lotus
#

& intersects two types and returns the common.

uneven sandal
#

I see, so it filters out what is not string

frank lotus
#

TS type system is modeled after set theory, & is just like intersecting two sets.