summaryrefslogtreecommitdiff
path: root/src/misc
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-05-01 19:31:34 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-05-01 19:31:34 +0900
commita9fc176c3c85920fd56f261a30db59c19108b644 (patch)
tree240b612ed03e871e33540dc6b60c29330aa0c33a /src/misc
parentRefactor (diff)
downloadsharkey-a9fc176c3c85920fd56f261a30db59c19108b644.tar.gz
sharkey-a9fc176c3c85920fd56f261a30db59c19108b644.tar.bz2
sharkey-a9fc176c3c85920fd56f261a30db59c19108b644.zip
Fix types
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/aiscript/index.ts8
-rw-r--r--src/misc/aiscript/type-checker.ts10
2 files changed, 9 insertions, 9 deletions
diff --git a/src/misc/aiscript/index.ts b/src/misc/aiscript/index.ts
index d36c27f942..16f80830ff 100644
--- a/src/misc/aiscript/index.ts
+++ b/src/misc/aiscript/index.ts
@@ -44,9 +44,9 @@ export type Variable = Block & {
name: string;
};
-export type Type = 'string' | 'number' | 'boolean' | 'stringArray';
+export type Type = 'string' | 'number' | 'boolean' | 'stringArray' | null;
-export const funcDefs = {
+export const funcDefs: Record<string, { in: any[]; out: any; category: string; icon: any; }> = {
if: { in: ['boolean', 0, 0], out: 0, category: 'flow', icon: faShareAlt, },
for: { in: ['number', 'function'], out: null, category: 'flow', icon: faRecycle, },
not: { in: ['boolean'], out: 'boolean', category: 'logical', icon: faFlag, },
@@ -81,7 +81,7 @@ export const funcDefs = {
seedRandomPick: { in: [null, 0], out: 0, category: 'random', icon: faDice, },
};
-export const literalDefs = {
+export const literalDefs: Record<string, { out: any; category: string; icon: any; }> = {
text: { out: 'string', category: 'value', icon: faQuoteRight, },
multiLineText: { out: 'string', category: 'value', icon: faAlignLeft, },
textList: { out: 'stringArray', category: 'value', icon: faList, },
@@ -105,7 +105,7 @@ export function isFnBlock(block: Block): block is FnBlock {
export type PageVar = { name: string; value: any; type: Type; };
-export const envVarsDef = {
+export const envVarsDef: Record<string, Type> = {
AI: 'string',
URL: 'string',
VERSION: 'string',
diff --git a/src/misc/aiscript/type-checker.ts b/src/misc/aiscript/type-checker.ts
index 35dee36bf1..c40c844ea4 100644
--- a/src/misc/aiscript/type-checker.ts
+++ b/src/misc/aiscript/type-checker.ts
@@ -58,7 +58,7 @@ export class ASTypeChecker {
}
@autobind
- public getExpectedType(v: Block, slot: number): Type | null {
+ public getExpectedType(v: Block, slot: number): Type {
const def = funcDefs[v.type];
if (def == null) {
throw new Error('Unknown type: ' + v.type);
@@ -86,7 +86,7 @@ export class ASTypeChecker {
}
@autobind
- public infer(v: Block): Type | null {
+ public infer(v: Block): Type {
if (v.type === null) return null;
if (v.type === 'text') return 'string';
if (v.type === 'multiLineText') return 'string';
@@ -140,19 +140,19 @@ export class ASTypeChecker {
}
@autobind
- public getVarsByType(type: Type | null): Variable[] {
+ public getVarsByType(type: Type): Variable[] {
if (type == null) return this.variables;
return this.variables.filter(x => (this.infer(x) === null) || (this.infer(x) === type));
}
@autobind
- public getEnvVarsByType(type: Type | null): string[] {
+ public getEnvVarsByType(type: Type): string[] {
if (type == null) return Object.keys(envVarsDef);
return Object.entries(envVarsDef).filter(([k, v]) => v === null || type === v).map(([k, v]) => k);
}
@autobind
- public getPageVarsByType(type: Type | null): string[] {
+ public getPageVarsByType(type: Type): string[] {
if (type == null) return this.pageVars.map(v => v.name);
return this.pageVars.filter(v => type === v.type).map(v => v.name);
}