Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix part of #7165: Remove some more any types #9754

Merged
merged 3 commits into from Jul 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions core/templates/components/oppia-angular-root.component.ts
Expand Up @@ -498,9 +498,6 @@ import { StateObjectFactory } from 'domain/state/StateObjectFactory';
import { StateParamChangesService } from
// eslint-disable-next-line max-len
'components/state-editor/state-editor-properties-services/state-param-changes.service';
import { StatePropertyService } from
// eslint-disable-next-line max-len
'components/state-editor/state-editor-properties-services/state-property.service';
Comment on lines -501 to -503
Copy link
Contributor Author

@nishantwrp nishantwrp Jul 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it from here because it should not be used directly but should be inherited first.

import { StateRecordedVoiceoversService } from
// eslint-disable-next-line max-len
'components/state-editor/state-editor-properties-services/state-recorded-voiceovers.service';
Expand Down Expand Up @@ -845,7 +842,6 @@ export class OppiaAngularRootComponent implements AfterViewInit {
static stateNameService: StateNameService;
static stateObjectFactory: StateObjectFactory;
static stateParamChangesService: StateParamChangesService;
static statePropertyService: StatePropertyService;
static stateRecordedVoiceoversService: StateRecordedVoiceoversService;
static stateSolicitAnswerDetailsService: StateSolicitAnswerDetailsService;
static stateSolutionService: StateSolutionService;
Expand Down Expand Up @@ -1130,7 +1126,6 @@ private stateInteractionStatsService: StateInteractionStatsService,
private stateNameService: StateNameService,
private stateObjectFactory: StateObjectFactory,
private stateParamChangesService: StateParamChangesService,
private statePropertyService: StatePropertyService,
private stateRecordedVoiceoversService: StateRecordedVoiceoversService,
private stateSolicitAnswerDetailsService: StateSolicitAnswerDetailsService,
private stateSolutionService: StateSolutionService,
Expand Down Expand Up @@ -1416,7 +1411,6 @@ private writtenTranslationsObjectFactory: WrittenTranslationsObjectFactory
OppiaAngularRootComponent.stateNameService = this.stateNameService;
OppiaAngularRootComponent.stateObjectFactory = this.stateObjectFactory;
OppiaAngularRootComponent.stateParamChangesService = this.stateParamChangesService;
OppiaAngularRootComponent.statePropertyService = this.statePropertyService;
OppiaAngularRootComponent.stateRecordedVoiceoversService = this.stateRecordedVoiceoversService;
OppiaAngularRootComponent.stateSolicitAnswerDetailsService = this.stateSolicitAnswerDetailsService;
OppiaAngularRootComponent.stateSolutionService = this.stateSolutionService;
Expand Down
Expand Up @@ -23,12 +23,13 @@ import { StatePropertyService } from
// eslint-disable-next-line max-len
'components/state-editor/state-editor-properties-services/state-property.service';
import { UtilsService } from 'services/utils.service';
import { SubtitledHtml } from 'domain/exploration/SubtitledHtmlObjectFactory';

@Injectable({
providedIn: 'root'
})
// TODO(sll): Add validation.
export class StateContentService extends StatePropertyService {
export class StateContentService extends StatePropertyService<SubtitledHtml> {
constructor(alertsService: AlertsService, utilsService: UtilsService) {
super(alertsService, utilsService);
this.setterMethodKey = 'saveStateContent';
Expand Down
Expand Up @@ -25,12 +25,15 @@ import { StatePropertyService } from
// eslint-disable-next-line max-len
'components/state-editor/state-editor-properties-services/state-property.service';
import { UtilsService } from 'services/utils.service';
import { IInteractionCustomizationArgs } from
'interactions/customization-args-defs';

@Injectable({
providedIn: 'root'
})
// TODO(sll): Add validation.
export class StateCustomizationArgsService extends StatePropertyService {
export class StateCustomizationArgsService extends
StatePropertyService<IInteractionCustomizationArgs> {
constructor(alertsService: AlertsService, utilsService: UtilsService) {
super(alertsService, utilsService);
this.setterMethodKey = 'saveInteractionCustomizationArgs';
Expand Down
Expand Up @@ -17,23 +17,22 @@
*/

import { TestBed } from '@angular/core/testing';
import { UtilsService } from 'services/utils.service';
import { AlertsService } from 'services/alerts.service';
import { HintObjectFactory } from 'domain/exploration/HintObjectFactory';
/* eslint-disable max-len */
import { StateHintsService } from 'components/state-editor/state-editor-properties-services/state-hints.service';
/* eslint-disable max-len */

describe('State hints service', () => {
let shs: StateHintsService = null;
let alertsService : AlertsService;
let utilsService : UtilsService;
let hof: HintObjectFactory = null;

beforeEach(() => {
TestBed.configureTestingModule({
providers: [StateHintsService]
providers: [StateHintsService, HintObjectFactory]
});

shs = TestBed.get(StateHintsService);
hof = TestBed.get(HintObjectFactory);
});

it('should called the constructor', () =>{
Expand All @@ -43,11 +42,12 @@ describe('State hints service', () => {
it('should called setActiveHintIndex after init', () =>{
spyOn(shs, 'setActiveHintIndex');
const StateName = 'Introduction';
const value = {0: {
_html: '<p>math</p>',
_contentId: 'hint_1'
}
};
const value = [{
hint_content: {
html: '<p>math</p>',
content_id: 'hint_1'
}
}].map(item => hof.createFromBackendDict(item));
shs.init(StateName, value);
expect(shs.setActiveHintIndex).toHaveBeenCalled();
});
Expand Down
Expand Up @@ -19,6 +19,7 @@ import { downgradeInjectable } from '@angular/upgrade/static';
import { Injectable } from '@angular/core';

import { AlertsService } from 'services/alerts.service';
import { Hint } from 'domain/exploration/HintObjectFactory';
import { StatePropertyService } from
// eslint-disable-next-line max-len
'components/state-editor/state-editor-properties-services/state-property.service';
Expand All @@ -27,7 +28,7 @@ import { UtilsService } from 'services/utils.service';
@Injectable({
providedIn: 'root'
})
export class StateHintsService extends StatePropertyService {
export class StateHintsService extends StatePropertyService<Hint[]> {
private activeHintIndex: number;
constructor(alertsService: AlertsService, utilsService: UtilsService) {
super(alertsService, utilsService);
Expand All @@ -42,7 +43,7 @@ export class StateHintsService extends StatePropertyService {
this.activeHintIndex = index;
}

init(stateName: string, value: any): void {
init(stateName: string, value: Hint[]): void {
super.init(stateName, value);
this.setActiveHintIndex(null);
}
Expand Down
Expand Up @@ -28,7 +28,7 @@ import { UtilsService } from 'services/utils.service';
providedIn: 'root'
})
// TODO(sll): Add validation.
export class StateInteractionIdService extends StatePropertyService {
export class StateInteractionIdService extends StatePropertyService<string> {
constructor(alertsService: AlertsService, utilsService: UtilsService) {
super(alertsService, utilsService);
this.setterMethodKey = 'saveInteractionId';
Expand Down
Expand Up @@ -20,6 +20,7 @@ import { downgradeInjectable } from '@angular/upgrade/static';
import { Injectable } from '@angular/core';

import { AlertsService } from 'services/alerts.service';
import { ParamChange } from 'domain/exploration/ParamChangeObjectFactory';
import { StatePropertyService } from
// eslint-disable-next-line max-len
'components/state-editor/state-editor-properties-services/state-property.service';
Expand All @@ -29,7 +30,8 @@ import { UtilsService } from 'services/utils.service';
providedIn: 'root'
})
// TODO(sll): Add validation.
export class StateParamChangesService extends StatePropertyService {
export class StateParamChangesService extends
StatePropertyService<ParamChange[]> {
constructor(alertsService: AlertsService, utilsService: UtilsService) {
super(alertsService, utilsService);
this.setterMethodKey = 'saveStateParamChanges';
Expand Down
Expand Up @@ -24,35 +24,36 @@ import cloneDeep from 'lodash/cloneDeep';
import { AlertsService } from 'services/alerts.service';
import { UtilsService } from 'services/utils.service';

/**
* NOTE TO DEVELOPERS: This class should not be used to create objects directly.
* This class should be first inherited to a other class. And a type argument
* with the type of state property should be passed.
*
* Example usage:
* class ExampleClass extends StatePropertyService<string> {
* ...
* }
*
* This will initialize the class with the type of properties like displayed,
* savedMomento etc. to be string.
*/
@Injectable({
providedIn: 'root'
})
export class StatePropertyService {
export class StatePropertyService<StatePropertyType> {
// The name of the setter method in ExplorationStatesService for this
// property. THIS MUST BE SPECIFIED BY SUBCLASSES.
setterMethodKey: string;
// TODO(#7165): Replace 'any' with the exact type. This has been kept
// as any since type of displayed depends on the property for which the
// value is provided. We need to create different domain objects for
// various properties and decide type of displayed according to that.
displayed: any;
displayed: StatePropertyType;
stateName: string;
// TODO(#7165): Replace 'any' with the exact type. This has been kept
// as any since type of savedMemento depends on the property for which the
// value is provided. We need to create different domain objects for
// various properties and decide type of savedMemento according to that.
savedMemento: any;
savedMemento: StatePropertyType;

constructor(private alertsService: AlertsService,
private utilsService: UtilsService) {
this.setterMethodKey = null;
}

// TODO(#7165): Replace 'any' with the exact type. This has been kept
// as any since type of value depends on the property for which the
// value is provided. We need to create different domain objects for
// various properties and decide type of value according to that.
init(stateName: string, value: any): void {
init(stateName: string, value: StatePropertyType): void {
if (this.setterMethodKey === null) {
throw new Error('State property setter method key cannot be null.');
}
Expand All @@ -74,22 +75,14 @@ export class StatePropertyService {

// Transforms the given value into a normalized form. THIS CAN BE
// OVERRIDDEN BY SUBCLASSES. The default behavior is to do nothing.
// TODO(#7165): Replace 'any' with the exact type. This has been kept
// as any since type of value depends on the property for which the
// value is provided. We need to create different domain objects for
// various properties and decide type of value according to that.
_normalize(value: any): any {
_normalize(value: StatePropertyType): StatePropertyType {
return value;
}

// Validates the given value and returns a boolean stating whether it
// is valid or not. THIS CAN BE OVERRIDDEN BY SUBCLASSES. The default
// behavior is to always return true.
// TODO(#7165): Replace 'any' with the exact type. This has been kept
// as any since type of value depends on the property for which the
// value is provided. We need to create different domain objects for
// various properties and decide type of value according to that.
_isValid(value: any): boolean {
_isValid(value: StatePropertyType): boolean {
return true;
}

Expand Down
Expand Up @@ -23,12 +23,15 @@ import { AlertsService } from 'services/alerts.service';
import { StatePropertyService } from
// eslint-disable-next-line max-len
'components/state-editor/state-editor-properties-services/state-property.service';
import { RecordedVoiceovers } from
'domain/exploration/RecordedVoiceoversObjectFactory';
import { UtilsService } from 'services/utils.service';

@Injectable({
providedIn: 'root'
})
export class StateRecordedVoiceoversService extends StatePropertyService {
export class StateRecordedVoiceoversService extends
StatePropertyService<RecordedVoiceovers> {
constructor(alertsService: AlertsService, utilsService: UtilsService) {
super(alertsService, utilsService);
this.setterMethodKey = 'saveRecordedVoiceovers';
Expand Down
Expand Up @@ -27,7 +27,8 @@ import { UtilsService } from 'services/utils.service';
@Injectable({
providedIn: 'root'
})
export class StateSolicitAnswerDetailsService extends StatePropertyService {
export class StateSolicitAnswerDetailsService extends
StatePropertyService<boolean> {
constructor(alertsService: AlertsService, utilsService: UtilsService) {
super(alertsService, utilsService);
this.setterMethodKey = 'saveSolicitAnswerDetails';
Expand Down
Expand Up @@ -19,6 +19,7 @@ import { downgradeInjectable } from '@angular/upgrade/static';
import { Injectable } from '@angular/core';

import { AlertsService } from 'services/alerts.service';
import { Solution } from 'domain/exploration/SolutionObjectFactory';
import { StatePropertyService } from
// eslint-disable-next-line max-len
'components/state-editor/state-editor-properties-services/state-property.service';
Expand All @@ -27,7 +28,7 @@ import { UtilsService } from 'services/utils.service';
@Injectable({
providedIn: 'root'
})
export class StateSolutionService extends StatePropertyService {
export class StateSolutionService extends StatePropertyService<Solution> {
constructor(alertsService: AlertsService, utilsService: UtilsService) {
super(alertsService, utilsService);
this.setterMethodKey = 'saveSolution';
Expand Down
Expand Up @@ -23,11 +23,14 @@ import { StatePropertyService } from
// eslint-disable-next-line max-len
'components/state-editor/state-editor-properties-services/state-property.service';
import { UtilsService } from 'services/utils.service';
import { WrittenTranslations } from
'domain/exploration/WrittenTranslationsObjectFactory';

@Injectable({
providedIn: 'root'
})
export class StateWrittenTranslationsService extends StatePropertyService {
export class StateWrittenTranslationsService extends
StatePropertyService<WrittenTranslations> {
constructor(alertsService: AlertsService, utilsService: UtilsService) {
super(alertsService, utilsService);
this.setterMethodKey = 'saveWrittenTranslations';
Expand Down
Expand Up @@ -20,17 +20,16 @@
import { downgradeInjectable } from '@angular/upgrade/static';
import { Injectable } from '@angular/core';

import { Outcome } from 'domain/exploration/OutcomeObjectFactory';

export class AnswerClassificationResult {
// TODO(#7165): Replace 'any' with the exact type. This has been kept as
// 'any' because 'outcome' is an outcome domain object and this can be
// directly typed to 'Outcome' type once 'OutcomeObjectFactory' is upgraded.
outcome: any;
outcome: Outcome;
answerGroupIndex: number;
ruleIndex: number;
classificationCategorization: string;

constructor(
outcome: any, answerGroupIndex: number, ruleIndex: number,
outcome: Outcome, answerGroupIndex: number, ruleIndex: number,
classificationCategorization: string) {
this.outcome = outcome;
this.answerGroupIndex = answerGroupIndex;
Expand All @@ -43,11 +42,8 @@ export class AnswerClassificationResult {
providedIn: 'root'
})
export class AnswerClassificationResultObjectFactory {
// TODO(#7165): Replace 'any' with the exact type. This has been kept as
// 'any' because 'outcome' is an outcome domain object and this can be
// directly typed to 'Outcome' type once 'OutcomeObjectFactory' is upgraded.
createNew(
outcome: any, answerGroupIndex: number, ruleIndex: number,
outcome: Outcome, answerGroupIndex: number, ruleIndex: number,
classificationCategorization: string): AnswerClassificationResult {
return new AnswerClassificationResult(
outcome, answerGroupIndex, ruleIndex, classificationCategorization);
Expand Down