字段定义

export enum Sex {
  Male = 'Male',
  Female = 'Female',
  Other = 'Other'
}

export interface PersonA {
  __typename: Sex.Male;
  age: number;
}

export interface PersonB {
  __typename: Sex.Female;
  name: string;
}
export enum PatientTypes{
  CreateNewPatientStudy='CreateNewPatientStudy'
}

export const PatientType='Patient' as const;
export const PatientType = "patientConst" as const;

export interface TagID<Id, Tag> {
  readonly id: Id;
  readonly __typename: Tag;
}

export interface TypedItem<T, Id, D, R> extends TagID<Id, T> {
  data: D;
  relation: R;
}

export type Patient = TypedItem<
  typeof PatientType,
  string,
  {
    readonly name: string;
    readonly birthday: Date;
    readonly external_id: string;
  },
  {}
>;

// 联合类型

比如定义一个name, birthday, external_id, __typename的接口,可这样:

export type PatientCerten = Patient['data'] & {__typname: string}
export namespace gantry {
  export enum GantryMessageTypes {
    CTGantryRotateStart = 'CTGantryRotateStart',
    CTGantryRotateStop = 'CTGantryRotateStop',
  }
  export interface CTGantryRotateStart {
    __typename: GantryMessageTypes.CTGantryRotateStart;
    velocity: number;
  }

  export interface CTGantryRotateStop {
    __typename: GantryMessageTypes.CTGantryRotateStop;
  }
}
export namespace status {
  export enum TableStatus {
    Moving = "moving",
    Unlock = "unlock",
  }

  export enum Connection {
    Connected = "connected",
    Disconnected = "disconnected",
  }
}
export type ScoutAngle = 0 | 90 | 180 | 270;
export const ScoutAngle: ReadonlyArray<ScoutAngle> = [0, 90, 180, 270];
export enum HintMessageTypes {
  ShowExposureHint = 'ShowExposureHint',
  CancelExposureHint = 'CancelExposureHint'
}

export interface ShowExposureHint {
  __typename: HintMessageTypes.ShowExposureHint;
  event:HintMessageTypes.ShowExposureHint
}
export interface CancelExposureHint {
  __typename: HintMessageTypes.CancelExposureHint;
  event:HintMessageTypes.CancelExposureHint
}

export type CTHintMessage =
  | ShowExposureHint
  | CancelExposureHint;
export const enum ScanTypes {
  ScanAxial = 'ScanAxial',
  ScanPET = 'ScanPET'
}

export interface ScanAxial {
  name: string;
  direction: Direction;
}
export interface ScanPET {
  name: string;
  state: ScanPETState;
}

export type ScanAxialItem = TypedItem<
  ScanTypes.ScanAxial,
  string,
  ScanAxial,
  ScanRelation
>;
export type ScanPETItem = TypedItem<
  ScanTypes.ScanPET,
  string,
  ScanPET,
  ScanRelation
>;

export interface ScanRelation {
  readonly children_ids: string[];
  readonly container_info?: {
    id: Protocol['id'];
    index: number;
  };
}

  _test: string = 'sss';
  set test(e: string) {
    this._test = e;
  }

  get test() {
    return this._test;
  }

  onStart() {
    const a = this.test;
    console.log(a)
  }

// 打印 sss

 

function toValue<T extends { value: R }, R>(xs: T[]): R[] {
  return xs.map(x => x.value as R);
}

interface SelectedFilters {
  focus: Focus[];
  FFS: FFS[];
  location: Region[];
  voltage: TubeVoltage[];
  bowtie: BowtieFilterSize[];
}

  currentSelectedFilters() {
    return {
      focus: toValue<SelectOption<Focus>, Focus>(this.focusSelected),
      FFS: toValue<SelectOption<FFS>, FFS>(this.FFSSelected),
      location: toValue<SelectOption<Region>, Region>(this.locationSelected),
      voltage: toValue<SelectOption<TubeVoltage>, TubeVoltage>(
        this.voltageSelected as SelectOption<TubeVoltage>[]
      ),
      bowtie: toValue<SelectOption<BowtieFilterSize>, BowtieFilterSize>(
        this.bowtieSelected
      )
    };
  }

  _selectedFilters: SelectedFilters = this.currentSelectedFilters();
  get bowtieSelected() {
    return this._bowtieSelected;
  }
  set bowtieSelected(value: SelectOption<BowtieFilterSize>[]) {
    this._bowtieSelected = value;
    this.selectedFilters = this.currentSelectedFilters();
  }

  onStart() {
    super.onStart('fast');
    const selected = this.selectedFilters;
    const action = {
      __typename: calibration.CalibrationMessageTypes.FastCalibration,
      calibration_type: 'fast',
      air_calibration: {
        ffs: selected.FFS,
        focal_spot_size: selected.focus,
        bowtie: selected.bowtie,
        tube_voltage: selected.voltage
      }
    } as calibration.CTFastCalibration;
    this.service.ctsMachine.calibration.run(action);

   console.log(currentSelectedFilters());
  }

// 如果打印currentSelectedFilters()这个函数,截图如下:

 


export interface SelectOption<T> {
  value: T;
  shown: string;
}

// 1
let a: SelectOption<number> = {
  value: 31313,
  shown: 'sss'
};

// 2
const da: SelectOption<{ large: 'large'; small: 'small' }>[] = [
  {
    value: { large: 'large', small: 'small' },
    shown: 'ss'
  },
  {
    value: { large: 'large', small: 'small' },
    shown: 'sssssssssssssss'
  }
];

// 3
export enum Focus {
  large = 'large',
  small = 'small',
}
const test: SelectOption<Focus>[] = [
  {
    value: Focus.large,
    shown: 'ss'
  }
];
function toValue<T extends { value: R }, R>(xs: T[]): R[] {
  return xs.map(x => x.value as R);
}
function x() {
  const test: SelectOption<Focus>[] = [
    {
      value: Focus.large,
      shown: 'ss'
    }
  ];
  return { a: toValue<SelectOption<Focus>, Focus>(test), b: 'ssss' };
}
interface SelectOption<T> {
  value: T;
  shown: string;
}

const test1: SelectOption<Focus> = {
  value: Focus.large,
  shown: 'dd'
};

type Test<T extends { value: any }> = {
  a: T;
  b: string;
};

const test2: Test<SelectOption<Focus>> = {
  a: { value: Focus.large, shown: 'dd' },
  b: 'dd'
};

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值