代码之家  ›  专栏  ›  技术社区  ›  Brent

配置增强类型以添加自定义类型脚本交集类型

  •  0
  • Brent  · 技术社区  · 6 年前

    我使用reinforced.typings fluent配置api(胸膜方法)将我的c dto映射到typescript接口,生成一个文件。

    目前我得到了(正确的)输出,比如

    export interface ICourseDto
    {
       start: Date;
       facultyMeetingRoom: IRoomDto;
       courseParticipants: ICourseParticipantDto[];
       ...
    }
    export interface IRoomDto ...
    

    理想情况下,我希望:

    1. 添加 import breeze from 'breeze-client' 到生成的typescript文件的开头
    2. 更改复杂属性的类型,以便上面的输出

    -

    export interface ICourseDto
    {
        start: Date;
        facultyMeetingRoom: IRoomDto & breeze.Entity;
        courseParticipants: (ICourseParticipantDto & breeze.Entity)[];
        ...
    

    对于reinforced.typings fluent配置,这可能吗?如果可能,我需要什么配置代码来实现它?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Pavel B. Novikov    6 年前

    实现您想要的最简单的方法是(其中s是configurationbuilder):

    s.Global(a => a.UseModules());
    s.AddImport("breeze", "breeze-client");
    
    var mySpecialTypes = typeof(IBreezeEntity).Assembly.GetTypes()
        .Where(d => typeof(IBreezeEntity).IsAssignableFrom(d));
    
    foreach (var type in mySpecialTypes)
    {
        s.Substitute(type, new RtSimpleTypeName($"I{type.Name} & breeze.Entity"));
    }
    

    加强。打字也能保留遗产。考虑从公共类型/接口派生实体并导出它。

    推荐文章