Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.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
Javascript Docz:如何将除接口之外的Typescript定义呈现为道具_Javascript_Typescript_Typescript Typings - Fatal编程技术网

Javascript Docz:如何将除接口之外的Typescript定义呈现为道具

Javascript Docz:如何将除接口之外的Typescript定义呈现为道具,javascript,typescript,typescript-typings,Javascript,Typescript,Typescript Typings,我们正在用Docz记录我们的类型定义。它在接口方面工作得很好,但是作为道具向Docz组件提供接口之外的任何东西似乎都无法呈现任何东西 我想知道如何呈现枚举或联合类型,并使其能够在mdx中呈现 它们在docz文件中的使用方式如下: interface.tsx: import { UserOrganisation, UserLevel } from "~/packages/database-interfaces/src"; export const UserLevelC = (props:

我们正在用Docz记录我们的类型定义。它在接口方面工作得很好,但是作为道具向Docz组件提供接口之外的任何东西似乎都无法呈现任何东西

我想知道如何呈现枚举或联合类型,并使其能够在mdx中呈现

它们在docz文件中的使用方式如下:

interface.tsx:

import {
  UserOrganisation,
  UserLevel
} from "~/packages/database-interfaces/src";

export const UserLevelC = (props: UserLevel) => {};
export const UserOrganisationC = (props: UserOrganisation) => {};
index.mdx:

---
name: users
menu: Database/Realtime
---

import { Props } from "docz";
import {
  UserLevelC,
  UserOrganisationC
} from "./Interface.tsx";


# Interface

## Properties

### Type UserOrganisation

<Props of={UserOrganisationC} />

### Type UserLevel

<Props of={UserLevelC} />
这样呈现(注意下面的“UserLevel”类型仅呈现为水平线):

作为参考,我们还尝试定义/导出以下方法:

export type foo = 'option1' | 'option2';
export enum foo = 'option1' | 'option2';
export const enum foo = 'option1' | 'option2';
如您所见,呈现的是接口,但不是此类型/枚举等

奇怪的是,如果相同类型的枚举字符串/联合类型被声明为接口的属性,而不是它自己的类型:

export interface UserOrganisation {
  level: 'employee' | 'owner' | 'admin' | 'disabled';
  name: string;
}
Docz可以在呈现界面时显示它,如下所示:

但是,当您尝试将其提取到自己的类型(我们需要这样做,因为其他接口在多个位置使用了此类型和其他类型)时,是什么都没有呈现的时候


任何帮助都将不胜感激,谢谢

级别:“员工”|“所有者”|“管理员”|“禁用”
works您可以将类型声明为:

type UserLevel = 'employee' | 'owner' | 'admin' | 'disabled';

级别:“员工”|“所有者”|“管理员”|“禁用”
works您可以将类型声明为:

type UserLevel = 'employee' | 'owner' | 'admin' | 'disabled';

您好,basarat,谢谢。是的,我们已经尝试过了,正如这里提到的:
export type foo='option1'|'option2';导出枚举foo='option1'|'option2';导出常量枚举foo=foo='option1'|'option2'export type foo='option1'|'option2';导出枚举foo='option1'|'option2';导出常量枚举foo=foo='option1'|'option2'