type Product = {
name: string;
price: number;
}
// Utility Type A
type Keys<T> = keyof T & string;
// Utility Type A without "& string"
type Keys<T> = keyof T & string;
type KeysOfProduct = Keys<Product>
Given the above condition, what are the differences when we use Utility Type A or Utility Type A without "& string"
The
& stringis used to eliminate any keys of the object which are not strings. In other words, it gets rid of numbers and symbols. YourProducttype doesn't have any of these, but different objects might.For example:
Playground Link