Skip to content

Commit

Permalink
strict typing [#586]
Browse files Browse the repository at this point in the history
  • Loading branch information
Blodir committed Nov 4, 2024
1 parent 98e949a commit 46b8b17
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import { TranslateService } from '@ngx-translate/core';
changeDetection: ChangeDetectionStrategy.OnPush
})
export class CitableDownloadComponent implements OnInit {
downloadRequest$: Observable<DownloadRequestResponse>;
id: string;
downloadRequest$!: Observable<DownloadRequestResponse>;
id: string | undefined;

isDownloadRequest = isDownloadRequest;
asDownloadRequest = asDownloadRequest;
Expand Down
18 changes: 9 additions & 9 deletions projects/laji/src/app/+user/friends/friends.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import { of as ObservableOf } from 'rxjs';
templateUrl: './friends.component.html'
})
export class FriendsComponent implements OnInit, OnChanges {
@Input() profile!: Profile;
@Input() usersProfile!: Profile;

@Input() profile: Profile;
@Input() usersProfile: Profile;

public user;
public requestSend = false;
public friends = [];
private lastId: string;
private lastId: string | undefined;

constructor(private userService: UserService,
private personService: PersonApi,
Expand Down Expand Up @@ -51,7 +49,8 @@ export class FriendsComponent implements OnInit, OnChanges {
}

alreadyFriends() {
return this.usersProfile.friends && this.usersProfile.friends.indexOf(this.profile.userID) > -1;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this.usersProfile.friends && this.usersProfile.friends.indexOf(this.profile.userID!) > -1;
}

sendFriendRequest(profileKy: string) {
Expand All @@ -64,7 +63,7 @@ export class FriendsComponent implements OnInit, OnChanges {
);
}

removeFriend(userId, block = false) {
removeFriend(userId: string, block = false) {
this.translateService.get(['friend.blockConfirm', 'friend.removeConfirm']).pipe(
switchMap(translation => this.dialogService.confirm(block ? translation['friend.blockConfirm'] : translation['friend.removeConfirm'])),
switchMap((confirm) => confirm ?
Expand All @@ -77,8 +76,9 @@ export class FriendsComponent implements OnInit, OnChanges {
);
}

removeBlock(userId) {
this.usersProfile.blocked = this.usersProfile.blocked.filter(id => id !== userId);
removeBlock(userId: string) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.usersProfile.blocked = this.usersProfile.blocked!.filter(id => id !== userId);
this.personService.personUpdateProfileByToken(this.usersProfile, this.userService.getToken())
.subscribe(
profile => this.usersProfile = profile,
Expand Down
27 changes: 17 additions & 10 deletions projects/laji/src/app/+user/profile/profile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { environment } from '../../../environments/environment';
})
export class ProfileComponent implements OnInit, OnDestroy {

currentProfile: Profile;
userProfile: Profile;
currentProfile!: Profile;
userProfile!: Profile;

public isCurrentUser = false;
public userId = '';
Expand All @@ -28,7 +28,7 @@ export class ProfileComponent implements OnInit, OnDestroy {
public loading = true;
public personSelfUrl = '/';

private subProfile: Subscription;
private subProfile!: Subscription;
intellectualRightsArray: Profile.IntellectualRights[] = [
Profile.IntellectualRights.intellectualRightsCCBYSA4,
Profile.IntellectualRights.intellectualRightsCCBYNC4,
Expand Down Expand Up @@ -64,10 +64,12 @@ export class ProfileComponent implements OnInit, OnDestroy {
const null$ = ObservableOf(null);
const userProfile$ = this.personService.personFindProfileByToken(this.userService.getToken()).pipe(catchError(() => null$));
return ObservableForkJoin(
currentUser.id
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
currentUser!.id
? userProfile$
: empty$,
currentUser.id === id
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
currentUser!.id === id
? userProfile$
: this.personService.personFindProfileByUserId(id).pipe(catchError(() => empty$))
).pipe(
Expand All @@ -81,7 +83,8 @@ export class ProfileComponent implements OnInit, OnDestroy {
})
).subscribe(
({id, currentUser, userProfile, currentProfile}) => {
this.isCurrentUser = id === currentUser.id;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.isCurrentUser = id === currentUser!.id;
this.userId = id;
this.isCreate = !userProfile;
this.currentProfile = prepareProfile(currentProfile, currentUser);
Expand Down Expand Up @@ -146,10 +149,14 @@ export class ProfileComponent implements OnInit, OnDestroy {
settings: {
...this.userProfile.settings,
defaultMediaMetadata: {
...this.userProfile.settings.defaultMediaMetadata,
capturerVerbatim: this.currentProfile?.settings?.defaultMediaMetadata?.capturerVerbatim,
intellectualOwner: this.currentProfile?.settings?.defaultMediaMetadata?.intellectualOwner,
intellectualRights: this.currentProfile?.settings?.defaultMediaMetadata?.intellectualRights
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
...this.userProfile.settings!.defaultMediaMetadata,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
capturerVerbatim: this.currentProfile?.settings?.defaultMediaMetadata?.capturerVerbatim!,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
intellectualOwner: this.currentProfile?.settings?.defaultMediaMetadata?.intellectualOwner!,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
intellectualRights: this.currentProfile?.settings?.defaultMediaMetadata?.intellectualRights!
}
}
};
Expand Down
8 changes: 4 additions & 4 deletions projects/laji/src/app/app-routing.modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ const rootRouting = {
};

Object.keys(Global.oldThemeRouting).forEach(path => {
rootRouting[path] = `/project/${Global.oldThemeRouting[path]}`;
rootRouting[<keyof typeof rootRouting>path] = `/project/${Global.oldThemeRouting[<keyof typeof Global.oldThemeRouting>path]}`;
});

const redirectsEn: Routes = [];
const redirectsSv: Routes = [];
const redirectsFi: Routes = [];

redirectsEn.push(...Object.keys(rootRouting).map<Route>(path => ({path, redirectTo: `/en${rootRouting[path]}`, pathMatch: 'full'})));
redirectsSv.push(...Object.keys(rootRouting).map<Route>(path => ({path, redirectTo: `/sv${rootRouting[path]}`, pathMatch: 'full'})));
redirectsFi.push(...Object.keys(rootRouting).map<Route>(path => ({path, redirectTo: `${rootRouting[path]}`, pathMatch: 'full'})));
redirectsEn.push(...Object.keys(rootRouting).map<Route>(path => ({path, redirectTo: `/en${rootRouting[<keyof typeof rootRouting>path]}`, pathMatch: 'full'})));
redirectsSv.push(...Object.keys(rootRouting).map<Route>(path => ({path, redirectTo: `/sv${rootRouting[<keyof typeof rootRouting>path]}`, pathMatch: 'full'})));
redirectsFi.push(...Object.keys(rootRouting).map<Route>(path => ({path, redirectTo: `${rootRouting[<keyof typeof rootRouting>path]}`, pathMatch: 'full'})));

const routesWithLang: Routes = [
{path: 'in', children: [
Expand Down
4 changes: 2 additions & 2 deletions projects/laji/src/app/locale/locale.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { PlatformService } from '../root/platform.service';

export abstract class LocaleComponent {

@LocalStorage(LAST_LANG_KEY) protected lastLang;
@LocalStorage(LAST_LANG_KEY) protected lastLang: string | undefined;

protected constructor(
protected platformService: PlatformService,
) {}

protected setLocale(lang) {
protected setLocale(lang: string) {
if (this.platformService.isBrowser) {
this.lastLang = lang;
try {
Expand Down
2 changes: 1 addition & 1 deletion projects/laji/src/app/locale/localize-in.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { GraphQLService } from '../graph-ql/service/graph-ql.service';
providedIn: 'root'
})
export class LocalizeInGuard {
@LocalStorage(LAST_LANG_KEY, 'en') protected lastLang;
@LocalStorage(LAST_LANG_KEY, 'en') protected lastLang: string | undefined;

constructor(
private router: Router,
Expand Down
5 changes: 3 additions & 2 deletions projects/laji/src/app/locale/localize-router.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const LANGUAGES: string[] = (environment as any).languages ?? ['fi', 'en'
@Injectable()
export class LocalizeRouterService {

static translatePath(path: string, lang): string {
static translatePath(path: string, lang: string): string {
const reg = new RegExp('^\/(in|' + LANGUAGES.join('|') + ')\\b'); // /^\/(in|en|sv|fi)\b/

if (path.match(reg)) {
Expand Down Expand Up @@ -40,7 +40,8 @@ export class LocalizeRouterService {
const result: any[] = [];
(query as Array<any>).forEach((segment: any, index: number) => {
if (index === 0 && typeof segment === 'string' && segment.startsWith('/')) {
result.push(LocalizeRouterService.translatePath(segment, lang));
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
result.push(LocalizeRouterService.translatePath(segment, lang!));
} else {
result.push(segment);
}
Expand Down
6 changes: 3 additions & 3 deletions projects/laji/src/app/locale/localize.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { Subscription } from 'rxjs';
})
export class LocalizePipe implements PipeTransform, OnDestroy {
private value: any = '';
private lastKey: string | any[];
private lastLanguage: string;
private subLang: Subscription;
private lastKey!: string | any[];
private lastLanguage: string | undefined;
private subLang: Subscription | undefined;

constructor(
private localizeRouterService: LocalizeRouterService,
Expand Down
4 changes: 2 additions & 2 deletions projects/laji/src/app/root/coordinate-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const getGeometryFromFeatureCollection = (featureCollection: any) => {
}
return {
type: 'GeometryCollection',
geometries: featureCollection.features.map(feature => feature.geometry)
geometries: featureCollection.features.map((feature: any) => feature.geometry)
};
}
return undefined;
Expand Down Expand Up @@ -104,7 +104,7 @@ export const convertEtrsToWgs = (lat: any, lng: any) => (
MapUtil.convertLatLng([lat, lng], 'EPSG:3067', 'WGS84')
);

const pad = (value) => {
const pad = (value: any) => {
value = '' + value;
return value + '0000000'.slice(value.length);
};
3 changes: 2 additions & 1 deletion projects/laji/src/app/root/platform.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export class PlatformService {
@Inject(PLATFORM_ID) private platformId: Object, // eslint-disable-line @typescript-eslint/ban-types
@Inject(DOCUMENT) public document: Document,
) {
this.window = document.defaultView;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.window = document.defaultView!;
}

get isBrowser(): boolean {
Expand Down

0 comments on commit 46b8b17

Please sign in to comment.