在TypeScript中使用部分映射类型时,为什么类型保护的行为会有所不同

cow*_*ill 8 typescript

使用以下代码编译tsc --strictNullChecks失败error TS2339: Property 'name' does not exist on type '{}'.

type Obj = {} | undefined;

type User = {
  email: string;
  password: string;
  name: string;
};

type PartialUser = Partial<User>;

function isUser(obj: Obj): obj is PartialUser {
  return true;
}

function getUserName(obj: Obj) {
  if (isUser(obj)) {
    return obj.name;
  }

  return '';
}
Run Code Online (Sandbox Code Playgroud)

不过,如果我更换type PartialUser = Partial<User>;

type PartialUser = {
  email?: string;
  password?: string;
  name?: string;
};
Run Code Online (Sandbox Code Playgroud)

一切都很笨拙.

有一些可用的解决方法,但我很好奇为什么会这样.PartialUser的这两个定义不应该在功能上等同吗?我在版本3.1.3