From efc4b1fa4ea54f02e476d2690c64448c2dc7c5fc Mon Sep 17 00:00:00 2001 From: Oliver Wipfli Date: Sun, 18 Jul 2021 19:23:55 +0200 Subject: [PATCH] Cast style-spec types to Type --- .../expression/definitions/assertion.ts | 2 +- src/style-spec/expression/definitions/at.ts | 4 +- src/style-spec/expression/definitions/case.ts | 2 +- .../expression/definitions/coalesce.ts | 2 +- .../expression/definitions/coercion.ts | 2 +- .../expression/definitions/collator.ts | 8 +- .../expression/definitions/comparison.ts | 8 +- .../expression/definitions/format.ts | 10 +- .../expression/definitions/image.ts | 4 +- src/style-spec/expression/definitions/in.ts | 8 +- .../expression/definitions/index.ts | 248 +++++++++--------- .../expression/definitions/index_of.ts | 10 +- .../expression/definitions/interpolate.ts | 4 +- .../expression/definitions/length.ts | 2 +- .../expression/definitions/match.ts | 2 +- .../expression/definitions/number_format.ts | 12 +- .../expression/definitions/slice.ts | 8 +- src/style-spec/expression/definitions/step.ts | 2 +- .../expression/definitions/within.ts | 2 +- src/style-spec/expression/types.ts | 4 +- 20 files changed, 172 insertions(+), 172 deletions(-) diff --git a/src/style-spec/expression/definitions/assertion.ts b/src/style-spec/expression/definitions/assertion.ts index d1a820a2ba..b5da69d925 100644 --- a/src/style-spec/expression/definitions/assertion.ts +++ b/src/style-spec/expression/definitions/assertion.ts @@ -75,7 +75,7 @@ class Assertion implements Expression { const parsed = []; for (; i < args.length; i++) { - const input = context.parse(args[i], i, ValueType); + const input = context.parse(args[i], i, ValueType as Type); if (!input) return null; parsed.push(input); } diff --git a/src/style-spec/expression/definitions/at.ts b/src/style-spec/expression/definitions/at.ts index 875e1543ad..be16aaf4e1 100644 --- a/src/style-spec/expression/definitions/at.ts +++ b/src/style-spec/expression/definitions/at.ts @@ -23,8 +23,8 @@ class At implements Expression { if (args.length !== 3) return context.error(`Expected 2 arguments, but found ${args.length - 1} instead.`) as null; - const index = context.parse(args[1], 1, NumberType); - const input = context.parse(args[2], 2, array(context.expectedType || ValueType)); + const index = context.parse(args[1], 1, NumberType as Type); + const input = context.parse(args[2], 2, array((context.expectedType || ValueType) as Type)); if (!index || !input) return null; diff --git a/src/style-spec/expression/definitions/case.ts b/src/style-spec/expression/definitions/case.ts index 28e343d2b2..62b5fa8fdb 100644 --- a/src/style-spec/expression/definitions/case.ts +++ b/src/style-spec/expression/definitions/case.ts @@ -34,7 +34,7 @@ class Case implements Expression { const branches = []; for (let i = 1; i < args.length - 1; i += 2) { - const test = context.parse(args[i], i, BooleanType); + const test = context.parse(args[i], i, BooleanType as Type); if (!test) return null; const result = context.parse(args[i + 1], i + 1, outputType); diff --git a/src/style-spec/expression/definitions/coalesce.ts b/src/style-spec/expression/definitions/coalesce.ts index 1eda5d8e90..b05e6b996d 100644 --- a/src/style-spec/expression/definitions/coalesce.ts +++ b/src/style-spec/expression/definitions/coalesce.ts @@ -45,7 +45,7 @@ class Coalesce implements Expression { parsedArgs.some(arg => checkSubtype(expectedType, arg.type)); return needsAnnotation ? - new Coalesce(ValueType, parsedArgs) : + new Coalesce(ValueType as Type, parsedArgs) : new Coalesce((outputType as any), parsedArgs); } diff --git a/src/style-spec/expression/definitions/coercion.ts b/src/style-spec/expression/definitions/coercion.ts index 59e4e90476..ebd6191c21 100644 --- a/src/style-spec/expression/definitions/coercion.ts +++ b/src/style-spec/expression/definitions/coercion.ts @@ -50,7 +50,7 @@ class Coercion implements Expression { const parsed = []; for (let i = 1; i < args.length; i++) { - const input = context.parse(args[i], i, ValueType); + const input = context.parse(args[i], i, ValueType as Type); if (!input) return null; parsed.push(input); } diff --git a/src/style-spec/expression/definitions/collator.ts b/src/style-spec/expression/definitions/collator.ts index 79f8df7488..230ca34595 100644 --- a/src/style-spec/expression/definitions/collator.ts +++ b/src/style-spec/expression/definitions/collator.ts @@ -13,7 +13,7 @@ export default class CollatorExpression implements Expression { locale: Expression | null; constructor(caseSensitive: Expression, diacriticSensitive: Expression, locale: Expression | null) { - this.type = CollatorType; + this.type = CollatorType as Type; this.locale = locale; this.caseSensitive = caseSensitive; this.diacriticSensitive = diacriticSensitive; @@ -28,16 +28,16 @@ export default class CollatorExpression implements Expression { return context.error(`Collator options argument must be an object.`) as null; const caseSensitive = context.parse( - options['case-sensitive'] === undefined ? false : options['case-sensitive'], 1, BooleanType); + options['case-sensitive'] === undefined ? false : options['case-sensitive'], 1, BooleanType as Type); if (!caseSensitive) return null; const diacriticSensitive = context.parse( - options['diacritic-sensitive'] === undefined ? false : options['diacritic-sensitive'], 1, BooleanType); + options['diacritic-sensitive'] === undefined ? false : options['diacritic-sensitive'], 1, BooleanType as Type); if (!diacriticSensitive) return null; let locale = null; if (options['locale']) { - locale = context.parse(options['locale'], 1, StringType); + locale = context.parse(options['locale'], 1, StringType as Type); if (!locale) return null; } diff --git a/src/style-spec/expression/definitions/comparison.ts b/src/style-spec/expression/definitions/comparison.ts index ef84d95c46..279e3965f6 100644 --- a/src/style-spec/expression/definitions/comparison.ts +++ b/src/style-spec/expression/definitions/comparison.ts @@ -68,7 +68,7 @@ function makeComparison(op: ComparisonOperator, compareBasic, compareWithCollato hasUntypedArgument: boolean; constructor(lhs: Expression, rhs: Expression, collator?: Expression | null) { - this.type = BooleanType; + this.type = BooleanType as Type; this.lhs = lhs; this.rhs = rhs; this.collator = collator; @@ -81,12 +81,12 @@ function makeComparison(op: ComparisonOperator, compareBasic, compareWithCollato const op: ComparisonOperator = (args[0] as any); - let lhs = context.parse(args[1], 1, ValueType); + let lhs = context.parse(args[1], 1, ValueType as Type); if (!lhs) return null; if (!isComparableType(op, lhs.type)) { return context.concat(1).error(`"${op}" comparisons are not supported for type '${toString(lhs.type)}'.`) as null; } - let rhs = context.parse(args[2], 2, ValueType); + let rhs = context.parse(args[2], 2, ValueType as Type); if (!rhs) return null; if (!isComparableType(op, rhs.type)) { return context.concat(2).error(`"${op}" comparisons are not supported for type '${toString(rhs.type)}'.`) as null; @@ -121,7 +121,7 @@ function makeComparison(op: ComparisonOperator, compareBasic, compareWithCollato ) { return context.error(`Cannot use collator to compare non-string types.`) as null; } - collator = context.parse(args[3], 3, CollatorType); + collator = context.parse(args[3], 3, CollatorType as Type); if (!collator) return null; } diff --git a/src/style-spec/expression/definitions/format.ts b/src/style-spec/expression/definitions/format.ts index e081fd6e0e..7375dc2289 100644 --- a/src/style-spec/expression/definitions/format.ts +++ b/src/style-spec/expression/definitions/format.ts @@ -29,7 +29,7 @@ export default class FormatExpression implements Expression { sections: Array; constructor(sections: Array) { - this.type = FormattedType; + this.type = FormattedType as Type; this.sections = sections; } @@ -53,19 +53,19 @@ export default class FormatExpression implements Expression { let scale = null; if (arg['font-scale']) { - scale = context.parse(arg['font-scale'], 1, NumberType); + scale = context.parse(arg['font-scale'], 1, NumberType as Type); if (!scale) return null; } let font = null; if (arg['text-font']) { - font = context.parse(arg['text-font'], 1, array(StringType)); + font = context.parse(arg['text-font'], 1, array(StringType as Type)); if (!font) return null; } let textColor = null; if (arg['text-color']) { - textColor = context.parse(arg['text-color'], 1, ColorType); + textColor = context.parse(arg['text-color'], 1, ColorType as Type); if (!textColor) return null; } @@ -74,7 +74,7 @@ export default class FormatExpression implements Expression { lastExpression.font = font; lastExpression.textColor = textColor; } else { - const content = context.parse(args[i], 1, ValueType); + const content = context.parse(args[i], 1, ValueType as Type); if (!content) return null; const kind = content.type.kind; diff --git a/src/style-spec/expression/definitions/image.ts b/src/style-spec/expression/definitions/image.ts index 6cabef56da..c1e5c38eb4 100644 --- a/src/style-spec/expression/definitions/image.ts +++ b/src/style-spec/expression/definitions/image.ts @@ -11,7 +11,7 @@ export default class ImageExpression implements Expression { input: Expression; constructor(input: Expression) { - this.type = ResolvedImageType; + this.type = ResolvedImageType as Type; this.input = input; } @@ -20,7 +20,7 @@ export default class ImageExpression implements Expression { return context.error(`Expected two arguments.`) as null; } - const name = context.parse(args[1], 1, StringType); + const name = context.parse(args[1], 1, StringType as Type); if (!name) return context.error(`No image name provided.`) as null; return new ImageExpression(name); diff --git a/src/style-spec/expression/definitions/in.ts b/src/style-spec/expression/definitions/in.ts index 5b85956ae5..e8dab5bff3 100644 --- a/src/style-spec/expression/definitions/in.ts +++ b/src/style-spec/expression/definitions/in.ts @@ -22,7 +22,7 @@ class In implements Expression { haystack: Expression; constructor(needle: Expression, haystack: Expression) { - this.type = BooleanType; + this.type = BooleanType as Type; this.needle = needle; this.haystack = haystack; } @@ -32,13 +32,13 @@ class In implements Expression { return context.error(`Expected 2 arguments, but found ${args.length - 1} instead.`) as null; } - const needle = context.parse(args[1], 1, ValueType); + const needle = context.parse(args[1], 1, ValueType as Type); - const haystack = context.parse(args[2], 2, ValueType); + const haystack = context.parse(args[2], 2, ValueType as Type); if (!needle || !haystack) return null; - if (!isValidType(needle.type, [BooleanType, StringType, NumberType, NullType, ValueType])) { + if (!isValidType(needle.type, [BooleanType as Type, StringType as Type, NumberType as Type, NullType as Type, ValueType as Type])) { return context.error(`Expected first argument to be of type boolean, string, number or null, but found ${toString(needle.type)} instead`) as null; } diff --git a/src/style-spec/expression/definitions/index.ts b/src/style-spec/expression/definitions/index.ts index 3767fd9069..73bfc58d02 100644 --- a/src/style-spec/expression/definitions/index.ts +++ b/src/style-spec/expression/definitions/index.ts @@ -125,99 +125,99 @@ function varargs(type: Type): Varargs { CompoundExpression.register(expressions, { 'error': [ - ErrorType, - [StringType], + ErrorType as Type, + [StringType as Type], (ctx, [v]) => { throw new RuntimeError(v.evaluate(ctx)); } ], 'typeof': [ - StringType, - [ValueType], + StringType as Type, + [ValueType as Type], (ctx, [v]) => typeToString(typeOf(v.evaluate(ctx))) ], 'to-rgba': [ - array(NumberType, 4), - [ColorType], + array(NumberType as Type, 4), + [ColorType as Type], (ctx, [v]) => { return v.evaluate(ctx).toArray(); } ], 'rgb': [ - ColorType, - [NumberType, NumberType, NumberType], + ColorType as Type, + [NumberType as Type, NumberType as Type, NumberType as Type], rgba ], 'rgba': [ - ColorType, - [NumberType, NumberType, NumberType, NumberType], + ColorType as Type, + [NumberType as Type, NumberType as Type, NumberType as Type, NumberType as Type], rgba ], 'has': { - type: BooleanType, + type: (BooleanType as Type), overloads: [ [ - [StringType], + [StringType as Type], (ctx, [key]) => has(key.evaluate(ctx), ctx.properties()) ], [ - [StringType, ObjectType], + [StringType as Type, ObjectType as Type], (ctx, [key, obj]) => has(key.evaluate(ctx), obj.evaluate(ctx)) ] ] }, 'get': { - type: ValueType, + type: (ValueType as Type), overloads: [ [ - [StringType], + [StringType as Type], (ctx, [key]) => get(key.evaluate(ctx), ctx.properties()) ], [ - [StringType, ObjectType], + [StringType as Type, ObjectType as Type], (ctx, [key, obj]) => get(key.evaluate(ctx), obj.evaluate(ctx)) ] ] }, 'feature-state': [ - ValueType, - [StringType], + ValueType as Type, + [StringType as Type], (ctx, [key]) => get(key.evaluate(ctx), ctx.featureState || {}) ], 'properties': [ - ObjectType, + ObjectType as Type, [], (ctx) => ctx.properties() ], 'geometry-type': [ - StringType, + StringType as Type, [], (ctx) => ctx.geometryType() ], 'id': [ - ValueType, + ValueType as Type, [], (ctx) => ctx.id() ], 'zoom': [ - NumberType, + NumberType as Type, [], (ctx) => ctx.globals.zoom ], 'heatmap-density': [ - NumberType, + NumberType as Type, [], (ctx) => ctx.globals.heatmapDensity || 0 ], 'line-progress': [ - NumberType, + NumberType as Type, [], (ctx) => ctx.globals.lineProgress || 0 ], 'accumulated': [ - ValueType, + ValueType as Type, [], (ctx) => ctx.globals.accumulated === undefined ? null : ctx.globals.accumulated ], '+': [ - NumberType, - varargs(NumberType), + NumberType as Type, + varargs(NumberType as Type), (ctx, args) => { let result = 0; for (const arg of args) { @@ -227,8 +227,8 @@ CompoundExpression.register(expressions, { } ], '*': [ - NumberType, - varargs(NumberType), + NumberType as Type, + varargs(NumberType as Type), (ctx, args) => { let result = 1; for (const arg of args) { @@ -238,115 +238,115 @@ CompoundExpression.register(expressions, { } ], '-': { - type: NumberType, + type: (NumberType as Type), overloads: [ [ - [NumberType, NumberType], + [NumberType as Type, NumberType as Type], (ctx, [a, b]) => a.evaluate(ctx) - b.evaluate(ctx) ], [ - [NumberType], + [NumberType as Type], (ctx, [a]) => -a.evaluate(ctx) ] ] }, '/': [ - NumberType, - [NumberType, NumberType], + NumberType as Type, + [NumberType as Type, NumberType as Type], (ctx, [a, b]) => a.evaluate(ctx) / b.evaluate(ctx) ], '%': [ - NumberType, - [NumberType, NumberType], + NumberType as Type, + [NumberType as Type, NumberType as Type], (ctx, [a, b]) => a.evaluate(ctx) % b.evaluate(ctx) ], 'ln2': [ - NumberType, + NumberType as Type, [], () => Math.LN2 ], 'pi': [ - NumberType, + NumberType as Type, [], () => Math.PI ], 'e': [ - NumberType, + NumberType as Type, [], () => Math.E ], '^': [ - NumberType, - [NumberType, NumberType], + NumberType as Type, + [NumberType as Type, NumberType as Type], (ctx, [b, e]) => Math.pow(b.evaluate(ctx), e.evaluate(ctx)) ], 'sqrt': [ - NumberType, - [NumberType], + NumberType as Type, + [NumberType as Type], (ctx, [x]) => Math.sqrt(x.evaluate(ctx)) ], 'log10': [ - NumberType, - [NumberType], + NumberType as Type, + [NumberType as Type], (ctx, [n]) => Math.log(n.evaluate(ctx)) / Math.LN10 ], 'ln': [ - NumberType, - [NumberType], + NumberType as Type, + [NumberType as Type], (ctx, [n]) => Math.log(n.evaluate(ctx)) ], 'log2': [ - NumberType, - [NumberType], + NumberType as Type, + [NumberType as Type], (ctx, [n]) => Math.log(n.evaluate(ctx)) / Math.LN2 ], 'sin': [ - NumberType, - [NumberType], + NumberType as Type, + [NumberType as Type], (ctx, [n]) => Math.sin(n.evaluate(ctx)) ], 'cos': [ - NumberType, - [NumberType], + NumberType as Type, + [NumberType as Type], (ctx, [n]) => Math.cos(n.evaluate(ctx)) ], 'tan': [ - NumberType, - [NumberType], + NumberType as Type, + [NumberType as Type], (ctx, [n]) => Math.tan(n.evaluate(ctx)) ], 'asin': [ - NumberType, - [NumberType], + NumberType as Type, + [NumberType as Type], (ctx, [n]) => Math.asin(n.evaluate(ctx)) ], 'acos': [ - NumberType, - [NumberType], + NumberType as Type, + [NumberType as Type], (ctx, [n]) => Math.acos(n.evaluate(ctx)) ], 'atan': [ - NumberType, - [NumberType], + NumberType as Type, + [NumberType as Type], (ctx, [n]) => Math.atan(n.evaluate(ctx)) ], 'min': [ - NumberType, - varargs(NumberType), + NumberType as Type, + varargs(NumberType as Type), (ctx, args) => Math.min(...args.map(arg => arg.evaluate(ctx))) ], 'max': [ - NumberType, - varargs(NumberType), + NumberType as Type, + varargs(NumberType as Type), (ctx, args) => Math.max(...args.map(arg => arg.evaluate(ctx))) ], 'abs': [ - NumberType, - [NumberType], + NumberType as Type, + [NumberType as Type], (ctx, [n]) => Math.abs(n.evaluate(ctx)) ], 'round': [ - NumberType, - [NumberType], + NumberType as Type, + [NumberType as Type], (ctx, [n]) => { const v = n.evaluate(ctx); // Javascript's Math.round() rounds towards +Infinity for halfway @@ -356,33 +356,33 @@ CompoundExpression.register(expressions, { } ], 'floor': [ - NumberType, - [NumberType], + NumberType as Type, + [NumberType as Type], (ctx, [n]) => Math.floor(n.evaluate(ctx)) ], 'ceil': [ - NumberType, - [NumberType], + NumberType as Type, + [NumberType as Type], (ctx, [n]) => Math.ceil(n.evaluate(ctx)) ], 'filter-==': [ - BooleanType, - [StringType, ValueType], + BooleanType as Type, + [StringType as Type, ValueType as Type], (ctx, [k, v]) => ctx.properties()[(k as any).value] === (v as any).value ], 'filter-id-==': [ - BooleanType, - [ValueType], + BooleanType as Type, + [ValueType as Type], (ctx, [v]) => ctx.id() === (v as any).value ], 'filter-type-==': [ - BooleanType, - [StringType], + BooleanType as Type, + [StringType as Type], (ctx, [v]) => ctx.geometryType() === (v as any).value ], 'filter-<': [ - BooleanType, - [StringType, ValueType], + BooleanType as Type, + [StringType as Type, ValueType as Type], (ctx, [k, v]) => { const a = ctx.properties()[(k as any).value]; const b = (v as any).value; @@ -390,8 +390,8 @@ CompoundExpression.register(expressions, { } ], 'filter-id-<': [ - BooleanType, - [ValueType], + BooleanType as Type, + [ValueType as Type], (ctx, [v]) => { const a = ctx.id(); const b = (v as any).value; @@ -399,8 +399,8 @@ CompoundExpression.register(expressions, { } ], 'filter->': [ - BooleanType, - [StringType, ValueType], + BooleanType as Type, + [StringType as Type, ValueType as Type], (ctx, [k, v]) => { const a = ctx.properties()[(k as any).value]; const b = (v as any).value; @@ -408,8 +408,8 @@ CompoundExpression.register(expressions, { } ], 'filter-id->': [ - BooleanType, - [ValueType], + BooleanType as Type, + [ValueType as Type], (ctx, [v]) => { const a = ctx.id(); const b = (v as any).value; @@ -417,8 +417,8 @@ CompoundExpression.register(expressions, { } ], 'filter-<=': [ - BooleanType, - [StringType, ValueType], + BooleanType as Type, + [StringType as Type, ValueType as Type], (ctx, [k, v]) => { const a = ctx.properties()[(k as any).value]; const b = (v as any).value; @@ -426,8 +426,8 @@ CompoundExpression.register(expressions, { } ], 'filter-id-<=': [ - BooleanType, - [ValueType], + BooleanType as Type, + [ValueType as Type], (ctx, [v]) => { const a = ctx.id(); const b = (v as any).value; @@ -435,8 +435,8 @@ CompoundExpression.register(expressions, { } ], 'filter->=': [ - BooleanType, - [StringType, ValueType], + BooleanType as Type, + [StringType as Type, ValueType as Type], (ctx, [k, v]) => { const a = ctx.properties()[(k as any).value]; const b = (v as any).value; @@ -444,8 +444,8 @@ CompoundExpression.register(expressions, { } ], 'filter-id->=': [ - BooleanType, - [ValueType], + BooleanType as Type, + [ValueType as Type], (ctx, [v]) => { const a = ctx.id(); const b = (v as any).value; @@ -453,46 +453,46 @@ CompoundExpression.register(expressions, { } ], 'filter-has': [ - BooleanType, - [ValueType], + BooleanType as Type, + [ValueType as Type], (ctx, [k]) => (k as any).value in ctx.properties() ], 'filter-has-id': [ - BooleanType, + BooleanType as Type, [], (ctx) => (ctx.id() !== null && ctx.id() !== undefined) ], 'filter-type-in': [ - BooleanType, - [array(StringType)], + BooleanType as Type, + [array(StringType as Type)], (ctx, [v]) => (v as any).value.indexOf(ctx.geometryType()) >= 0 ], 'filter-id-in': [ - BooleanType, - [array(ValueType)], + BooleanType as Type, + [array(ValueType as Type)], (ctx, [v]) => (v as any).value.indexOf(ctx.id()) >= 0 ], 'filter-in-small': [ - BooleanType, - [StringType, array(ValueType)], + BooleanType as Type, + [StringType as Type, array(ValueType as Type)], // assumes v is an array literal (ctx, [k, v]) => (v as any).value.indexOf(ctx.properties()[(k as any).value]) >= 0 ], 'filter-in-large': [ - BooleanType, - [StringType, array(ValueType)], + BooleanType as Type, + [StringType as Type, array(ValueType as Type)], // assumes v is a array literal with values sorted in ascending order and of a single type (ctx, [k, v]) => binarySearch(ctx.properties()[(k as any).value], (v as any).value, 0, (v as any).value.length - 1) ], 'all': { - type: BooleanType, + type: (BooleanType as Type), overloads: [ [ - [BooleanType, BooleanType], + [BooleanType as Type, BooleanType as Type], (ctx, [a, b]) => a.evaluate(ctx) && b.evaluate(ctx) ], [ - varargs(BooleanType), + varargs(BooleanType as Type), (ctx, args) => { for (const arg of args) { if (!arg.evaluate(ctx)) @@ -504,14 +504,14 @@ CompoundExpression.register(expressions, { ] }, 'any': { - type: BooleanType, + type: (BooleanType as Type), overloads: [ [ - [BooleanType, BooleanType], + [BooleanType as Type, BooleanType as Type], (ctx, [a, b]) => a.evaluate(ctx) || b.evaluate(ctx) ], [ - varargs(BooleanType), + varargs(BooleanType as Type), (ctx, args) => { for (const arg of args) { if (arg.evaluate(ctx)) @@ -523,13 +523,13 @@ CompoundExpression.register(expressions, { ] }, '!': [ - BooleanType, - [BooleanType], + BooleanType as Type, + [BooleanType as Type], (ctx, [b]) => !b.evaluate(ctx) ], 'is-supported-script': [ - BooleanType, - [StringType], + BooleanType as Type, + [StringType as Type], // At parse time this will always return true, so we need to exclude this expression with isGlobalPropertyConstant (ctx, [s]) => { const isSupportedScript = ctx.globals && ctx.globals.isSupportedScript; @@ -540,23 +540,23 @@ CompoundExpression.register(expressions, { } ], 'upcase': [ - StringType, - [StringType], + StringType as Type, + [StringType as Type], (ctx, [s]) => s.evaluate(ctx).toUpperCase() ], 'downcase': [ - StringType, - [StringType], + StringType as Type, + [StringType as Type], (ctx, [s]) => s.evaluate(ctx).toLowerCase() ], 'concat': [ - StringType, - varargs(ValueType), + StringType as Type, + varargs(ValueType as Type), (ctx, args) => args.map(arg => valueToString(arg.evaluate(ctx))).join('') ], 'resolved-locale': [ - StringType, - [CollatorType], + StringType as Type, + [CollatorType as Type], (ctx, [collator]) => collator.evaluate(ctx).resolvedLocale() ] }); diff --git a/src/style-spec/expression/definitions/index_of.ts b/src/style-spec/expression/definitions/index_of.ts index c06b90567c..1821840b73 100644 --- a/src/style-spec/expression/definitions/index_of.ts +++ b/src/style-spec/expression/definitions/index_of.ts @@ -23,7 +23,7 @@ class IndexOf implements Expression { fromIndex: Expression | undefined | null; constructor(needle: Expression, haystack: Expression, fromIndex?: Expression) { - this.type = NumberType; + this.type = NumberType as Type; this.needle = needle; this.haystack = haystack; this.fromIndex = fromIndex; @@ -34,17 +34,17 @@ class IndexOf implements Expression { return context.error(`Expected 3 or 4 arguments, but found ${args.length - 1} instead.`) as null; } - const needle = context.parse(args[1], 1, ValueType); + const needle = context.parse(args[1], 1, ValueType as Type); - const haystack = context.parse(args[2], 2, ValueType); + const haystack = context.parse(args[2], 2, ValueType as Type); if (!needle || !haystack) return null; - if (!isValidType(needle.type, [BooleanType, StringType, NumberType, NullType, ValueType])) { + if (!isValidType(needle.type, [BooleanType as Type, StringType as Type, NumberType as Type, NullType as Type, ValueType as Type])) { return context.error(`Expected first argument to be of type boolean, string, number or null, but found ${toString(needle.type)} instead`) as null; } if (args.length === 4) { - const fromIndex = context.parse(args[3], 3, NumberType); + const fromIndex = context.parse(args[3], 3, NumberType as Type); if (!fromIndex) return null; return new IndexOf(needle, haystack, fromIndex); } else { diff --git a/src/style-spec/expression/definitions/interpolate.ts b/src/style-spec/expression/definitions/interpolate.ts index 9cf0d603f3..c1762bf446 100644 --- a/src/style-spec/expression/definitions/interpolate.ts +++ b/src/style-spec/expression/definitions/interpolate.ts @@ -100,14 +100,14 @@ class Interpolate implements Expression { return context.error(`Expected an even number of arguments.`) as null; } - input = context.parse(input, 2, NumberType); + input = context.parse(input, 2, NumberType as Type); if (!input) return null; const stops: Stops = []; let outputType: Type = (null as any); if (operator === 'interpolate-hcl' || operator === 'interpolate-lab') { - outputType = ColorType; + outputType = ColorType as Type; } else if (context.expectedType && context.expectedType.kind !== 'value') { outputType = context.expectedType; } diff --git a/src/style-spec/expression/definitions/length.ts b/src/style-spec/expression/definitions/length.ts index e88258506a..937681f04b 100644 --- a/src/style-spec/expression/definitions/length.ts +++ b/src/style-spec/expression/definitions/length.ts @@ -13,7 +13,7 @@ class Length implements Expression { input: Expression; constructor(input: Expression) { - this.type = NumberType; + this.type = NumberType as Type; this.input = input; } diff --git a/src/style-spec/expression/definitions/match.ts b/src/style-spec/expression/definitions/match.ts index aeab8a8e76..07cf3996e6 100644 --- a/src/style-spec/expression/definitions/match.ts +++ b/src/style-spec/expression/definitions/match.ts @@ -86,7 +86,7 @@ class Match implements Expression { outputs.push(result); } - const input = context.parse(args[1], 1, ValueType); + const input = context.parse(args[1], 1, ValueType as Type); if (!input) return null; const otherwise = context.parse(args[args.length - 1], args.length - 1, outputType); diff --git a/src/style-spec/expression/definitions/number_format.ts b/src/style-spec/expression/definitions/number_format.ts index 4990e0289a..fc8aa94103 100644 --- a/src/style-spec/expression/definitions/number_format.ts +++ b/src/style-spec/expression/definitions/number_format.ts @@ -37,7 +37,7 @@ export default class NumberFormat implements Expression { currency: Expression | null, minFractionDigits: Expression | null, maxFractionDigits: Expression | null) { - this.type = StringType; + this.type = StringType as Type; this.number = number; this.locale = locale; this.currency = currency; @@ -49,7 +49,7 @@ export default class NumberFormat implements Expression { if (args.length !== 3) return context.error(`Expected two arguments.`) as null; - const number = context.parse(args[1], 1, NumberType); + const number = context.parse(args[1], 1, NumberType as Type); if (!number) return null; const options = (args[2] as any); @@ -58,25 +58,25 @@ export default class NumberFormat implements Expression { let locale = null; if (options['locale']) { - locale = context.parse(options['locale'], 1, StringType); + locale = context.parse(options['locale'], 1, StringType as Type); if (!locale) return null; } let currency = null; if (options['currency']) { - currency = context.parse(options['currency'], 1, StringType); + currency = context.parse(options['currency'], 1, StringType as Type); if (!currency) return null; } let minFractionDigits = null; if (options['min-fraction-digits']) { - minFractionDigits = context.parse(options['min-fraction-digits'], 1, NumberType); + minFractionDigits = context.parse(options['min-fraction-digits'], 1, NumberType as Type); if (!minFractionDigits) return null; } let maxFractionDigits = null; if (options['max-fraction-digits']) { - maxFractionDigits = context.parse(options['max-fraction-digits'], 1, NumberType); + maxFractionDigits = context.parse(options['max-fraction-digits'], 1, NumberType as Type); if (!maxFractionDigits) return null; } diff --git a/src/style-spec/expression/definitions/slice.ts b/src/style-spec/expression/definitions/slice.ts index 29b7b14cca..cbe29638fe 100644 --- a/src/style-spec/expression/definitions/slice.ts +++ b/src/style-spec/expression/definitions/slice.ts @@ -34,17 +34,17 @@ class Slice implements Expression { return context.error(`Expected 3 or 4 arguments, but found ${args.length - 1} instead.`) as null; } - const input = context.parse(args[1], 1, ValueType); - const beginIndex = context.parse(args[2], 2, NumberType); + const input = context.parse(args[1], 1, ValueType as Type); + const beginIndex = context.parse(args[2], 2, NumberType as Type); if (!input || !beginIndex) return null; - if (!isValidType(input.type, [array(ValueType), StringType, ValueType])) { + if (!isValidType(input.type, [array(ValueType as Type), StringType as Type, ValueType as Type])) { return context.error(`Expected first argument to be of type array or string, but found ${toString(input.type)} instead`) as null; } if (args.length === 4) { - const endIndex = context.parse(args[3], 3, NumberType); + const endIndex = context.parse(args[3], 3, NumberType as Type); if (!endIndex) return null; return new Slice(input.type, input, beginIndex, endIndex); } else { diff --git a/src/style-spec/expression/definitions/step.ts b/src/style-spec/expression/definitions/step.ts index 7593581b38..c24876066e 100644 --- a/src/style-spec/expression/definitions/step.ts +++ b/src/style-spec/expression/definitions/step.ts @@ -36,7 +36,7 @@ class Step implements Expression { return context.error(`Expected an even number of arguments.`) as null; } - const input = context.parse(args[1], 1, NumberType); + const input = context.parse(args[1], 1, NumberType as Type); if (!input) return null; const stops: Stops = []; diff --git a/src/style-spec/expression/definitions/within.ts b/src/style-spec/expression/definitions/within.ts index c34872d5cd..cf582ca601 100644 --- a/src/style-spec/expression/definitions/within.ts +++ b/src/style-spec/expression/definitions/within.ts @@ -286,7 +286,7 @@ class Within implements Expression { geometries: GeoJSONPolygons; constructor(geojson: GeoJSON, geometries: GeoJSONPolygons) { - this.type = BooleanType; + this.type = BooleanType as Type; this.geojson = geojson; this.geometries = geometries; } diff --git a/src/style-spec/expression/types.ts b/src/style-spec/expression/types.ts index 8df6b1ee44..c24e7e5c31 100644 --- a/src/style-spec/expression/types.ts +++ b/src/style-spec/expression/types.ts @@ -84,7 +84,7 @@ const valueMemberTypes = [ ColorType, FormattedType, ObjectType, - array(ValueType), + array(ValueType as ValueTypeT), ResolvedImageType ]; @@ -107,7 +107,7 @@ export function checkSubtype(expected: Type, t: Type): string | undefined | null return null; } else if (expected.kind === 'value') { for (const memberType of valueMemberTypes) { - if (!checkSubtype(memberType, t)) { + if (!checkSubtype(memberType as Type, t)) { return null; } }