属性 在类型上不存在:为什么 TypeScript 报错而 JavaScript 不报错?
Property does not exist on type: Why does TypeScript complain while JavaScript doesn't?
在下面的代码中
import { useMsal } from "@azure/msal-react";
function ProfileContent() {
const { instance, accounts } = useMsal();
const name = accounts[0] && accounts[0].name;
JavaScript
对此没有问题,代码按预期工作。但是当我将其设为 TypeScript
文件时,出现
的错误
Property 'name' does not exist on type 'Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>
是什么发生了如此巨大的变化,以至于 TypeScript 认为库中的 属性 甚至不存在?
浏览源代码,看起来他们可能在 IMsalContext
中使用了错误的类型。在 dev
分支上有一个带有消息 "Fix accounts type".
的提交
这是当前的released version, the dev branch version, the pull request, and the associated issue。
在下面的代码中
import { useMsal } from "@azure/msal-react";
function ProfileContent() {
const { instance, accounts } = useMsal();
const name = accounts[0] && accounts[0].name;
JavaScript
对此没有问题,代码按预期工作。但是当我将其设为 TypeScript
文件时,出现
Property 'name' does not exist on type 'Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>
是什么发生了如此巨大的变化,以至于 TypeScript 认为库中的 属性 甚至不存在?
浏览源代码,看起来他们可能在 IMsalContext
中使用了错误的类型。在 dev
分支上有一个带有消息 "Fix accounts type".
这是当前的released version, the dev branch version, the pull request, and the associated issue。