0

我正在尝试使用导航器检测勇敢。我参考了这篇文章,https://stackoverflow.com/a/60954062/14443512

我试过这个条件, (navigator.brave && await navigator.brave.isBrave() || false)

但我得到错误,Property 'brave' does not exist on type 'Navigator'.

我在这里缺少任何配置吗?

我的代码块,

export const errorMessage = (networkError: netError): string | undefined => {
    const {statusCode, message} = networkError;
    if (statusCode === undefined) {
        return message;
    }
    if (statusCode < 400) {
        return undefined;
    }
    switch (statusCode) {
        case 401:
            return 'authn error';
        case 403:
            if(navigator.brave && await navigator.brave.isBrave() || false)
            return 'browser not supported';

else 
return 'authz error';
        case 500:
            if (message.includes("invalid value")) {
                return invalidString;
            }
            break;
    }
    if (statusCode < 500) {
        return 'error';
    }
    return 'serverError';
};
4

1 回答 1

0

我认为声明应该是这样的:

export {}; // there must be at least one export in this file

declare global {
  interface Navigator {
    brave: {
      isBrave(): boolean;
    };
  }
  interface Global {
    document: Document;
    window: Window;
    navigator: Navigator,
  } 
}
于 2021-03-09T17:14:58.737 回答