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'
};