您能否将带有装饰器的Typescript类导出为普通类(没有装饰器)?

让我们说我有一个这样的课程:

import { Injectable } from '@nestjs/common';
import { IsString } from 'class-validator';
import { prop } from '@typegoose/typegoose';

@Injectable()
export class Human
{
    @prop({ unique: true })
    @IsString()
    readonly name: string;
}

问题是:我可以导出此类,以便接收端在没有装饰器的情况下获取它,如下所示:

class Human
{
    readonly name: string;
}

我想导出类(装饰器具有其他依赖项),以便导入该文件的文件不需要这些装饰器使用的依赖项,例如nestjs,class-validator和typegoose。

我试图不写出“只读名称:字符串;”不止一次。

zhaojiewww 回答:您能否将带有装饰器的Typescript类导出为普通类(没有装饰器)?

所以我想通了,部分要感谢zett42。

您可以在打字稿中定义 $ flutter pub get Error: No pubspec.yaml file found. This command should be run from the root of your Flutter project. Do not run this command from the root of your git clone of Flutter. ,因此,如果仅创建与类相等的类型,然后导出该类型,则将有效地导出没有装饰器的类定义。您也可以使用type进行操作,但是类型似乎更简洁。但是我不确定类型是否与接口相同,请阅读Typescript文档!

具有类型:

interfaces

具有接口:

export type THuman = Human;
本文链接:https://www.f2er.com/2818776.html

大家都在问