在以下代码中,additional-info
的类型应为QuestionsCreatedByUserForATagContext|StatusBarContext|PracticeQuestionContext|
PracticeQuestionListContext|QuestionDetailContext;
export class DialogServiceContext {
public ['sender-id']: ComponentAndServiceID;
public ['additional-info']: QuestionsCreatedByUserForATagContext|StatusBarContext|PracticeQuestionContext|
PracticeQuestionListContext|QuestionDetailContext;
public ['dialog-type']: DialogType;
constructor( senderID: ComponentAndServiceID,
additionalInfo: QuestionsCreatedByUserForATagContext|StatusBarContext|PracticeQuestionContext|
PracticeQuestionListContext|QuestionDetailContext,
dialogType: DialogType= DialogType.alert) {
this['sender-id'] = senderID;
this['additional-info'] = additionalInfo;
this['dialog-type'] = dialogType;
}
}
但是我仍然可以按如下方式使用它(向它传递SignupContext
类型的上下文。
showDialog(context: SignupContext) {
this.dialogService.emitDialogMessage(new DialogServiceContext(ComponentAndServiceID.SignupComponent, context));
}
为什么typescript
没有给出编译错误?