summaryrefslogtreecommitdiff
path: root/src/misc
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2019-04-13 01:43:22 +0900
committerGitHub <noreply@github.com>2019-04-13 01:43:22 +0900
commit987168b863c52d0548050ffbac569782bb9a8cef (patch)
treec9aa2243dcdcbd044688d201a51c601574bff259 /src/misc
parentFix bug (diff)
downloadsharkey-987168b863c52d0548050ffbac569782bb9a8cef.tar.gz
sharkey-987168b863c52d0548050ffbac569782bb9a8cef.tar.bz2
sharkey-987168b863c52d0548050ffbac569782bb9a8cef.zip
strictNullChecks (#4666)
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/acct/type.ts2
-rw-r--r--src/misc/convert-host.ts3
-rw-r--r--src/misc/detect-mine.ts2
-rw-r--r--src/misc/donwload-url.ts3
-rw-r--r--src/misc/fetch-meta.ts1
-rw-r--r--src/misc/fetch-proxy-account.ts3
-rw-r--r--src/misc/identifiable-error.ts2
-rw-r--r--src/misc/nyaize.ts4
-rw-r--r--src/misc/schema.ts4
9 files changed, 11 insertions, 13 deletions
diff --git a/src/misc/acct/type.ts b/src/misc/acct/type.ts
index c88a920c69..7f31257400 100644
--- a/src/misc/acct/type.ts
+++ b/src/misc/acct/type.ts
@@ -1,6 +1,6 @@
type Acct = {
username: string;
- host: string;
+ host: string | null;
};
export default Acct;
diff --git a/src/misc/convert-host.ts b/src/misc/convert-host.ts
index f7feebd55c..dbf7864550 100644
--- a/src/misc/convert-host.ts
+++ b/src/misc/convert-host.ts
@@ -2,7 +2,7 @@ import config from '../config';
import { toASCII } from 'punycode';
import { URL } from 'url';
-export function getFullApAccount(username: string, host: string) {
+export function getFullApAccount(username: string, host: string | null) {
return host ? `${username}@${toPuny(host)}` : `${username}@${toPuny(config.host)}`;
}
@@ -17,6 +17,5 @@ export function extractDbHost(uri: string) {
}
export function toPuny(host: string) {
- if (host == null) return null;
return toASCII(host.toLowerCase());
}
diff --git a/src/misc/detect-mine.ts b/src/misc/detect-mine.ts
index bbf49efc10..70d58ffe21 100644
--- a/src/misc/detect-mine.ts
+++ b/src/misc/detect-mine.ts
@@ -3,7 +3,7 @@ import fileType from 'file-type';
import checkSvg from '../misc/check-svg';
export async function detectMine(path: string) {
- return new Promise<[string, string]>((res, rej) => {
+ return new Promise<[string, string | null]>((res, rej) => {
const readable = fs.createReadStream(path);
readable
.on('error', rej)
diff --git a/src/misc/donwload-url.ts b/src/misc/donwload-url.ts
index 0dd4e4ef5d..167e01fdd1 100644
--- a/src/misc/donwload-url.ts
+++ b/src/misc/donwload-url.ts
@@ -1,5 +1,4 @@
import * as fs from 'fs';
-import * as URL from 'url';
import * as request from 'request';
import config from '../config';
import chalk from 'chalk';
@@ -26,7 +25,7 @@ export async function downloadUrl(url: string, path: string) {
rej(error);
});
- const requestUrl = URL.parse(url).pathname.match(/[^\u0021-\u00ff]/) ? encodeURI(url) : url;
+ const requestUrl = new URL(url).pathname.match(/[^\u0021-\u00ff]/) ? encodeURI(url) : url;
const req = request({
url: requestUrl,
diff --git a/src/misc/fetch-meta.ts b/src/misc/fetch-meta.ts
index d1483e9edb..cf1fc474ce 100644
--- a/src/misc/fetch-meta.ts
+++ b/src/misc/fetch-meta.ts
@@ -9,7 +9,6 @@ export default async function(): Promise<Meta> {
} else {
return Metas.save({
id: genId(),
- hiddenTags: []
} as Meta);
}
}
diff --git a/src/misc/fetch-proxy-account.ts b/src/misc/fetch-proxy-account.ts
index d60fa9b313..17b021e91e 100644
--- a/src/misc/fetch-proxy-account.ts
+++ b/src/misc/fetch-proxy-account.ts
@@ -1,8 +1,9 @@
import fetchMeta from './fetch-meta';
import { ILocalUser } from '../models/entities/user';
import { Users } from '../models';
+import { ensure } from '../prelude/ensure';
export async function fetchProxyAccount(): Promise<ILocalUser> {
const meta = await fetchMeta();
- return await Users.findOne({ username: meta.proxyAccount, host: null }) as ILocalUser;
+ return await Users.findOne({ username: meta.proxyAccount!, host: null }).then(ensure) as ILocalUser;
}
diff --git a/src/misc/identifiable-error.ts b/src/misc/identifiable-error.ts
index 1edd26cd18..2d7c6bd0c6 100644
--- a/src/misc/identifiable-error.ts
+++ b/src/misc/identifiable-error.ts
@@ -7,7 +7,7 @@ export class IdentifiableError extends Error {
constructor(id: string, message?: string) {
super(message);
- this.message = message;
+ this.message = message || '';
this.id = id;
}
}
diff --git a/src/misc/nyaize.ts b/src/misc/nyaize.ts
index 8b06300eab..918e7d63fd 100644
--- a/src/misc/nyaize.ts
+++ b/src/misc/nyaize.ts
@@ -3,7 +3,7 @@ export function nyaize(text: string): string {
// ja-JP
.replace(/な/g, 'にゃ').replace(/ナ/g, 'ニャ').replace(/ナ/g, 'ニャ')
// ko-KR
- .replace(/[나-낳]/g, (match: string) => String.fromCharCode(
- match.codePointAt(0) + '냐'.charCodeAt(0) - '나'.charCodeAt(0)
+ .replace(/[나-낳]/g, match => String.fromCharCode(
+ match.codePointAt(0)! + '냐'.charCodeAt(0) - '나'.charCodeAt(0)
));
}
diff --git a/src/misc/schema.ts b/src/misc/schema.ts
index e5c24dd468..7c17953d97 100644
--- a/src/misc/schema.ts
+++ b/src/misc/schema.ts
@@ -19,8 +19,8 @@ type MyType<T extends Schema> = {
export type SchemaType<p extends Schema> =
p['type'] extends 'number' ? number :
p['type'] extends 'string' ? string :
- p['type'] extends 'array' ? MyType<p['items']>[] :
- p['type'] extends 'object' ? ObjType<p['properties']> :
+ p['type'] extends 'array' ? MyType<NonNullable<p['items']>>[] :
+ p['type'] extends 'object' ? ObjType<NonNullable<p['properties']>> :
any;
export function convertOpenApiSchema(schema: Schema) {