Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
默认导出的TypeScriptp语法_Typescript - Fatal编程技术网

默认导出的TypeScriptp语法

默认导出的TypeScriptp语法,typescript,Typescript,我是打字新手 在此代码中 import { ITokenCache } from './tokens/token-cache'; import { ISession } from './session/session'; import { ISignInWithAuth0 } from './instance'; export default function createDummyBrowserInstance(): ISignInWithAuth0 & { isBrowser: b

我是打字新手

在此代码中

import { ITokenCache } from './tokens/token-cache';
import { ISession } from './session/session';
import { ISignInWithAuth0 } from './instance';

export default function createDummyBrowserInstance(): ISignInWithAuth0 & { isBrowser: boolean } {
  return {
    isBrowser: true,
    handleLogin: (): Promise<void> => {
      throw new Error('The handleLogin method can only be used from the server side');
    },
    handleLogout: (): Promise<void> => {
      throw new Error('The handleLogout method can only be used from the server side');
    },
    handleCallback: (): Promise<void> => {
      throw new Error('The handleCallback method can only be used from the server side');
    },
    handleProfile: (): Promise<void> => {
      throw new Error('The handleProfile method can only be used from the server side');
    },
    getSession: (): Promise<ISession | null | undefined> => {
      throw new Error('The getSession method can only be used from the server side');
    },
    requireAuthentication: () => (): Promise<void> => {
      throw new Error('The requireAuthentication method can only be used from the server side');
    },
    tokenCache: (): ITokenCache => {
      throw new Error('The tokenCache method can only be used from the server side');
    }
  };
}

你能帮忙吗?

这是退货类型

它使用。在本例中,它返回一个类型为ISignInWithAuth0的对象,并带有一个附加的布尔属性


我建议您阅读/浏览链接文档。

这是否回答了您的问题?函数createDummyBrowserInstance还返回一个对象。因此,导出的最终对象是来自return的ISignInWithAuth0&{isBrowser:boolean}&对象的组合,而不是。函数名和列后面的语法是返回类型。返回的对象需要遵守返回类型,并被类型化为返回类型。
export default function createDummyBrowserInstance(): ISignInWithAuth0 & { isBrowser: boolean } {