Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

类型定义问题 #30

Closed
wyswill opened this issue Aug 11, 2022 · 2 comments
Closed

类型定义问题 #30

wyswill opened this issue Aug 11, 2022 · 2 comments
Labels

Comments

@wyswill
Copy link

wyswill commented Aug 11, 2022

我在创建接口时如下定义

export interface ReqUpdate extends BaseRequest {
  id: number;
  info: {
    projectName?: string;
    projectOwner?: string;
    isDel?: boolean;
  };
}

或是

export type T_project_item = {
  id: number
  projectName: string
  projectOwner: string
  createTime: string
  updateTime: string
  isDel: boolean
}


export interface ReqUpdate extends BaseRequest {
  id: number;
  info: Pick<T_project_item,'id'>
}

可以正常编译通过,

但是我的自定义工具类型则报错

export type Nullable<T> = {
  [Key in keyof T]?: T[Key];
};

export interface ReqUpdate extends BaseRequest {
  id: number;
  info: Nullable<Pick<T_project_item,'isDel'| 'projectOwner'>>;
}
⨯ Cannot resolve type: {
  [Key in keyof T]?: T[Key];
}
    at ../../plugins/typeTool
⨯ ServiceProto 生成失败,请检查 TypeScript 代码是否编译报错: src/shared/protocols/serviceProto.ts

@k8w
Copy link
Owner

k8w commented Aug 11, 2022

暂时还不支持完整的 Mapped Type 和泛型,但支持部分工具类型,如 NonNullable Partial 等。
详见:支持的 TypeScript 类型

你的需求,可以用自带支持的 Partial<T> 来替代自定义的 Nullable<T>

@wyswill
Copy link
Author

wyswill commented Aug 11, 2022

暂时还不支持完整的 Mapped Type 和泛型,但支持部分工具类型,如 NonNullable Partial 等。 详见:支持的 TypeScript 类型

你的需求,可以用自带支持的 Partial<T> 来替代自定义的 Nullable<T>

cool!

@k8w k8w added the question label Aug 11, 2022
@k8w k8w closed this as completed Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants