'Why does keyof return a different result in this example

type NodeA = {
  type: 'A'
  name: string
  flag: number
}

type NodeB = {
  type: 'B'
  id: number
  flag: number
}
type Nodes = NodeA | NodeB

type test = {
  [P in keyof Nodes]: 21
}
// it return this
type test = {
    type: 21;
    flag: 21;
}

But when I use the generic,the results are completely different

type test<T> = {
  [P in keyof T]: 21
}
type test2 = test<Nodes>

test2 return like this type test2 = test | test

playground link



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source