From a9fc176c3c85920fd56f261a30db59c19108b644 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 1 May 2019 19:31:34 +0900 Subject: [PATCH] Fix types --- src/misc/aiscript/index.ts | 8 ++++---- src/misc/aiscript/type-checker.ts | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/misc/aiscript/index.ts b/src/misc/aiscript/index.ts index d36c27f94..16f80830f 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 = { 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 = { 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 = { AI: 'string', URL: 'string', VERSION: 'string', diff --git a/src/misc/aiscript/type-checker.ts b/src/misc/aiscript/type-checker.ts index 35dee36bf..c40c844ea 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); }