From c89656f3eeadf2cf92a1a304c877b0c4a8210a43 Mon Sep 17 00:00:00 2001 From: "John J. Camilleri" Date: Fri, 7 Jun 2019 10:06:19 +0200 Subject: [PATCH] More type fixes in gflib.ts after setting noImplicitAny --- src/runtime/typescript/gflib.ts | 50 ++++++++++++++-------------- src/runtime/typescript/tsconfig.json | 2 +- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/runtime/typescript/gflib.ts b/src/runtime/typescript/gflib.ts index f6a18954b..274b46b33 100644 --- a/src/runtime/typescript/gflib.ts +++ b/src/runtime/typescript/gflib.ts @@ -30,8 +30,8 @@ export class GFGrammar { input: string, fromLang: string, toLang: string - ): {[key: string]: {[key: string]: string}} { - let outputs = {} + ): {[key: string]: {[key: string]: string}[]} { + let outputs: {[key: string]: {[key: string]: string}[]} = {} let fromConcs = this.concretes if (fromLang) { fromConcs = {} @@ -48,7 +48,7 @@ export class GFGrammar { if (trees.length > 0) { outputs[c1] = [] for (let i in trees) { - outputs[c1][i] = new Object() + outputs[c1][i] = {} for (let c2 in toConcs) { outputs[c1][i][c2] = this.concretes[c2].linearize(trees[i]) } @@ -373,7 +373,7 @@ class GFConcrete { res.push({fid: fid, table: [[sym]]}) } } else { - let cs = [] + let cs: {fid: FId; table: Sym[][]}[] = [] for (let i in tree.args) { // TODO: we should handle the case for nondeterministic linearization cs.push(this.linearizeSyms(tree.args[i],tag + '-' + i)[0]) @@ -385,13 +385,13 @@ class GFConcrete { for (let i in this.lproductions[key]) { let rule = this.lproductions[key][i] - let row = { + let row: {fid: FId; table: Sym[][]} = { fid: rule.fid, table: [] } for (let j in rule.fun.lins) { let lin = rule.fun.lins[j] as Sym[] - let toks = [] + let toks: Sym[] = [] row.table[j] = toks lin.forEach((sym0: Sym): void => { @@ -422,7 +422,7 @@ class GFConcrete { } private syms2toks(syms: Sym[]): string[] { - let ts = [] + let ts: string[] = [] syms.forEach((sym0: Sym): void => { switch (sym0.id) { case 'KS': { @@ -850,36 +850,36 @@ class SymLit { */ class Trie { public value: T[] - private items: Trie[] + private items: {[key: string]: Trie} public constructor() { this.value = null - this.items = [] + this.items = {} } public insertChain(keys: string[], obj: T[]): void { - let node = this - for (let i in keys) { - let nnode = node.items[keys[i]] + let node: Trie = this + keys.forEach((key: string): void => { + let nnode = node.items[key] if (nnode == null) { nnode = new Trie() - node.items[keys[i]] = nnode + node.items[key] = nnode } node = nnode - } + }) node.value = obj } public insertChain1(keys: string[], obj: T): void { - let node = this - for (let i in keys) { - let nnode = node.items[keys[i]] + let node: Trie = this + keys.forEach((key: string): void => { + let nnode = node.items[key] if (nnode == null) { nnode = new Trie() - node.items[keys[i]] = nnode + node.items[key] = nnode } node = nnode - } + }) if (node.value == null) node.value = [obj] else @@ -1049,7 +1049,7 @@ class ParseState { if (fid < totalFIds) { return [new Fun('?')] } else { - let trees = [] + let trees: Fun[] = [] let rules = forest[fid] rules.forEach((rule: Rule): void => { @@ -1057,8 +1057,8 @@ class ParseState { trees.push((rule as Const).lit) } else { rule = rule as Apply - let arg_ix = [] - let arg_ts = [] + let arg_ix: number[] = [] + let arg_ts: Fun[][] = [] for (let k in rule.args) { arg_ix[k] = 0 arg_ts[k] = go(rule.args[k].fid) @@ -1343,7 +1343,7 @@ class Chart { } public expandForest(fid: FId): Apply[] { - let rules = [] + let rules: Apply[] = [] let forest = this.forest let go = function (rules0: Rule[]): void { @@ -1351,7 +1351,7 @@ class Chart { let rule = rules0[i] switch (rule.id) { case 'Apply': - rules.push(rule) + rules.push(rule as Apply) break case 'Coerce': go(forest[(rule as Coerce).arg]) @@ -1406,7 +1406,7 @@ class ActiveItem { } public shiftOverArg(i: number, fid: FId): ActiveItem { - let nargs = [] + let nargs: PArg[] = [] for (let k in this.args) { nargs[k] = this.args[k] } diff --git a/src/runtime/typescript/tsconfig.json b/src/runtime/typescript/tsconfig.json index 45c1de1e5..dc8bbb8e1 100644 --- a/src/runtime/typescript/tsconfig.json +++ b/src/runtime/typescript/tsconfig.json @@ -1,5 +1,5 @@ { "compilerOptions": { - "noImplicitAny": false + "noImplicitAny": true } }