From d8608429ef3ef3de3556697fbf9ec642a0a84b01 Mon Sep 17 00:00:00 2001 From: Krist Wongsuphasawat Date: Tue, 8 Jan 2019 01:35:16 +0700 Subject: [PATCH] Migrate @superset-ui/color to TypeScript (#69) * Refactor: Convert color to TS --- package.json | 4 +-- packages/superset-ui-color/package.json | 1 + ...espace.js => CategoricalColorNamespace.ts} | 33 ++++++++++++------- ...ColorScale.js => CategoricalColorScale.ts} | 14 +++++--- ...egoricalScheme.js => CategoricalScheme.ts} | 0 ... => CategoricalSchemeRegistrySingleton.ts} | 3 +- packages/superset-ui-color/src/ColorScheme.js | 10 ------ packages/superset-ui-color/src/ColorScheme.ts | 21 ++++++++++++ ...hemeRegistry.js => ColorSchemeRegistry.ts} | 6 +++- ...equentialScheme.js => SequentialScheme.ts} | 22 ++++++++----- ...s => SequentialSchemeRegistrySingleton.ts} | 3 +- .../categorical/{airbnb.js => airbnb.ts} | 0 .../colorSchemes/categorical/{d3.js => d3.ts} | 0 .../categorical/{google.js => google.ts} | 0 .../categorical/{lyft.js => lyft.ts} | 0 .../sequential/{common.js => common.ts} | 0 .../colorSchemes/sequential/{d3.js => d3.ts} | 0 .../src/{index.js => index.ts} | 3 +- ...tringifyAndTrim.js => stringifyAndTrim.ts} | 2 +- packages/superset-ui-color/src/types.ts | 5 +++ ...t.js => CategoricalColorNameSpace.test.ts} | 7 ++++ ....test.js => CategoricalColorScale.test.ts} | 2 +- ...olorScheme.test.js => ColorScheme.test.ts} | 5 --- ...ry.test.js => ColorSchemeRegistry.test.ts} | 0 ...cheme.test.js => SequentialScheme.test.ts} | 0 ...orSchemes.test.js => colorSchemes.test.ts} | 0 .../test/{index.test.js => index.test.ts} | 0 .../superset-ui-core/src/utils/isRequired.ts | 2 +- 28 files changed, 95 insertions(+), 48 deletions(-) rename packages/superset-ui-color/src/{CategoricalColorNamespace.js => CategoricalColorNamespace.ts} (62%) rename packages/superset-ui-color/src/{CategoricalColorScale.js => CategoricalColorScale.ts} (78%) rename packages/superset-ui-color/src/{CategoricalScheme.js => CategoricalScheme.ts} (100%) rename packages/superset-ui-color/src/{CategoricalSchemeRegistrySingleton.js => CategoricalSchemeRegistrySingleton.ts} (59%) delete mode 100644 packages/superset-ui-color/src/ColorScheme.js create mode 100644 packages/superset-ui-color/src/ColorScheme.ts rename packages/superset-ui-color/src/{ColorSchemeRegistry.js => ColorSchemeRegistry.ts} (52%) rename packages/superset-ui-color/src/{SequentialScheme.js => SequentialScheme.ts} (64%) rename packages/superset-ui-color/src/{SequentialSchemeRegistrySingleton.js => SequentialSchemeRegistrySingleton.ts} (60%) rename packages/superset-ui-color/src/colorSchemes/categorical/{airbnb.js => airbnb.ts} (100%) rename packages/superset-ui-color/src/colorSchemes/categorical/{d3.js => d3.ts} (100%) rename packages/superset-ui-color/src/colorSchemes/categorical/{google.js => google.ts} (100%) rename packages/superset-ui-color/src/colorSchemes/categorical/{lyft.js => lyft.ts} (100%) rename packages/superset-ui-color/src/colorSchemes/sequential/{common.js => common.ts} (100%) rename packages/superset-ui-color/src/colorSchemes/sequential/{d3.js => d3.ts} (100%) rename packages/superset-ui-color/src/{index.js => index.ts} (77%) rename packages/superset-ui-color/src/{stringifyAndTrim.js => stringifyAndTrim.ts} (57%) create mode 100644 packages/superset-ui-color/src/types.ts rename packages/superset-ui-color/test/{CategoricalColorNameSpace.test.js => CategoricalColorNameSpace.test.ts} (94%) rename packages/superset-ui-color/test/{CategoricalColorScale.test.js => CategoricalColorScale.test.ts} (98%) rename packages/superset-ui-color/test/{ColorScheme.test.js => ColorScheme.test.ts} (57%) rename packages/superset-ui-color/test/{ColorSchemeRegistry.test.js => ColorSchemeRegistry.test.ts} (100%) rename packages/superset-ui-color/test/{SequentialScheme.test.js => SequentialScheme.test.ts} (100%) rename packages/superset-ui-color/test/{colorSchemes.test.js => colorSchemes.test.ts} (100%) rename packages/superset-ui-color/test/{index.test.js => index.test.ts} (100%) diff --git a/package.json b/package.json index f9619f4242ed3..63275c9d72118 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ "build": "yarn run build:cjs && yarn run build:esm && yarn run type:dts", "build:cjs": "NODE_ENV=production beemo babel --extensions=\".js,.jsx,.ts,.tsx\" ./src --out-dir lib/ --minify --workspaces=\"@superset-ui/!(demo|generator-superset)\"", "build:esm": "NODE_ENV=production beemo babel --extensions=\".js,.jsx,.ts,.tsx\" ./src --out-dir esm/ --esm --minify --workspaces=\"@superset-ui/!(demo|generator-superset)\"", - "type": "NODE_ENV=production beemo typescript --workspaces=\"@superset-ui/(connection|core|chart)\" --noEmit", - "type:dts": "NODE_ENV=production beemo typescript --workspaces=\"@superset-ui/(connection|core|chart)\" --emitDeclarationOnly", + "type": "NODE_ENV=production beemo typescript --workspaces=\"@superset-ui/(connection|core|color|chart)\" --noEmit", + "type:dts": "NODE_ENV=production beemo typescript --workspaces=\"@superset-ui/(connection|core|color|chart)\" --emitDeclarationOnly", "lint": "beemo create-config prettier && beemo eslint \"./packages/*/{src,test,storybook}/**/*.{js,jsx,ts,tsx}\"", "lint:fix": "beemo create-config prettier && beemo eslint --fix \"./packages/*/{src,test,storybook}/**/*.{js,jsx,ts,tsx}\"", "jest": "beemo jest --color --coverage --react", diff --git a/packages/superset-ui-color/package.json b/packages/superset-ui-color/package.json index 057421bda73c7..3090ddb27bd0b 100644 --- a/packages/superset-ui-color/package.json +++ b/packages/superset-ui-color/package.json @@ -27,6 +27,7 @@ }, "dependencies": { "@superset-ui/core": "^0.7.0", + "@types/d3-scale": "^2.0.2", "d3-scale": "^2.1.2" } } diff --git a/packages/superset-ui-color/src/CategoricalColorNamespace.js b/packages/superset-ui-color/src/CategoricalColorNamespace.ts similarity index 62% rename from packages/superset-ui-color/src/CategoricalColorNamespace.js rename to packages/superset-ui-color/src/CategoricalColorNamespace.ts index 38a4ffae99bbe..5859f398c01dc 100644 --- a/packages/superset-ui-color/src/CategoricalColorNamespace.js +++ b/packages/superset-ui-color/src/CategoricalColorNamespace.ts @@ -1,24 +1,30 @@ import CategoricalColorScale from './CategoricalColorScale'; +import { ColorsLookup } from './types'; import getCategoricalSchemeRegistry from './CategoricalSchemeRegistrySingleton'; import stringifyAndTrim from './stringifyAndTrim'; export default class CategoricalColorNamespace { - constructor(name) { + name: string; + forcedItems: ColorsLookup; + scales: { + [key: string]: CategoricalColorScale; + }; + + constructor(name: string) { this.name = name; this.scales = {}; this.forcedItems = {}; } - getScale(schemeId) { - const id = schemeId || getCategoricalSchemeRegistry().getDefaultKey(); + getScale(schemeId?: string) { + const id = schemeId || getCategoricalSchemeRegistry().getDefaultKey() || ''; const scale = this.scales[id]; if (scale) { return scale; } - const newScale = new CategoricalColorScale( - getCategoricalSchemeRegistry().get(id).colors, - this.forcedItems, - ); + const scheme = getCategoricalSchemeRegistry().get(id); + + const newScale = new CategoricalColorScale((scheme && scheme.colors) || [], this.forcedItems); this.scales[id] = newScale; return newScale; @@ -31,17 +37,20 @@ export default class CategoricalColorNamespace { * @param {*} value value * @param {*} forcedColor color */ - setColor(value, forcedColor) { + setColor(value: string, forcedColor: string) { this.forcedItems[stringifyAndTrim(value)] = forcedColor; return this; } } -const namespaces = {}; +const namespaces: { + [key: string]: CategoricalColorNamespace; +} = {}; + export const DEFAULT_NAMESPACE = 'GLOBAL'; -export function getNamespace(name = DEFAULT_NAMESPACE) { +export function getNamespace(name: string = DEFAULT_NAMESPACE) { const instance = namespaces[name]; if (instance) { return instance; @@ -52,12 +61,12 @@ export function getNamespace(name = DEFAULT_NAMESPACE) { return newInstance; } -export function getColor(value, schemeId, namespace) { +export function getColor(value?: string, schemeId?: string, namespace?: string) { return getNamespace(namespace) .getScale(schemeId) .getColor(value); } -export function getScale(scheme, namespace) { +export function getScale(scheme?: string, namespace?: string) { return getNamespace(namespace).getScale(scheme); } diff --git a/packages/superset-ui-color/src/CategoricalColorScale.js b/packages/superset-ui-color/src/CategoricalColorScale.ts similarity index 78% rename from packages/superset-ui-color/src/CategoricalColorScale.js rename to packages/superset-ui-color/src/CategoricalColorScale.ts index 4d37a2da36198..92ec43383a9f6 100644 --- a/packages/superset-ui-color/src/CategoricalColorScale.js +++ b/packages/superset-ui-color/src/CategoricalColorScale.ts @@ -1,22 +1,28 @@ import { ExtensibleFunction } from '@superset-ui/core'; +import { ColorsLookup } from './types'; import stringifyAndTrim from './stringifyAndTrim'; export default class CategoricalColorScale extends ExtensibleFunction { + colors: string[]; + parentForcedColors?: ColorsLookup; + forcedColors: ColorsLookup; + seen: { [key: string]: number }; + /** * Constructor * @param {*} colors an array of colors * @param {*} parentForcedColors optional parameter that comes from parent * (usually CategoricalColorNamespace) and supersede this.forcedColors */ - constructor(colors, parentForcedColors) { - super((...args) => this.getColor(...args)); + constructor(colors: string[], parentForcedColors?: ColorsLookup) { + super((value: string) => this.getColor(value)); this.colors = colors; this.parentForcedColors = parentForcedColors; this.forcedColors = {}; this.seen = {}; } - getColor(value) { + getColor(value?: string) { const cleanedValue = stringifyAndTrim(value); const parentColor = this.parentForcedColors && this.parentForcedColors[cleanedValue]; @@ -46,7 +52,7 @@ export default class CategoricalColorScale extends ExtensibleFunction { * @param {*} value value * @param {*} forcedColor forcedColor */ - setColor(value, forcedColor) { + setColor(value: string, forcedColor: string) { this.forcedColors[stringifyAndTrim(value)] = forcedColor; return this; diff --git a/packages/superset-ui-color/src/CategoricalScheme.js b/packages/superset-ui-color/src/CategoricalScheme.ts similarity index 100% rename from packages/superset-ui-color/src/CategoricalScheme.js rename to packages/superset-ui-color/src/CategoricalScheme.ts diff --git a/packages/superset-ui-color/src/CategoricalSchemeRegistrySingleton.js b/packages/superset-ui-color/src/CategoricalSchemeRegistrySingleton.ts similarity index 59% rename from packages/superset-ui-color/src/CategoricalSchemeRegistrySingleton.js rename to packages/superset-ui-color/src/CategoricalSchemeRegistrySingleton.ts index 0a75cf6b96b5b..adcc04317267b 100644 --- a/packages/superset-ui-color/src/CategoricalSchemeRegistrySingleton.js +++ b/packages/superset-ui-color/src/CategoricalSchemeRegistrySingleton.ts @@ -1,7 +1,8 @@ import { makeSingleton } from '@superset-ui/core'; +import CategoricalScheme from './CategoricalScheme'; import ColorSchemeRegistry from './ColorSchemeRegistry'; -class CategoricalSchemeRegistry extends ColorSchemeRegistry {} +class CategoricalSchemeRegistry extends ColorSchemeRegistry {} const getInstance = makeSingleton(CategoricalSchemeRegistry); diff --git a/packages/superset-ui-color/src/ColorScheme.js b/packages/superset-ui-color/src/ColorScheme.js deleted file mode 100644 index bd01c6739ea96..0000000000000 --- a/packages/superset-ui-color/src/ColorScheme.js +++ /dev/null @@ -1,10 +0,0 @@ -import { isRequired } from '@superset-ui/core'; - -export default class ColorScheme { - constructor({ colors = isRequired('colors'), description = '', id = isRequired('id'), label }) { - this.id = id; - this.label = label || id; - this.colors = colors; - this.description = description; - } -} diff --git a/packages/superset-ui-color/src/ColorScheme.ts b/packages/superset-ui-color/src/ColorScheme.ts new file mode 100644 index 0000000000000..a15667592c807 --- /dev/null +++ b/packages/superset-ui-color/src/ColorScheme.ts @@ -0,0 +1,21 @@ +export interface ColorSchemeConfig { + colors: string[]; + description?: string; + id: string; + label?: string; +} + +export default class ColorScheme { + colors: string[]; + description: string; + id: string; + label: string; + + constructor(config: ColorSchemeConfig) { + const { colors, description = '', id, label } = config; + this.id = id; + this.label = label || id; + this.colors = colors; + this.description = description; + } +} diff --git a/packages/superset-ui-color/src/ColorSchemeRegistry.js b/packages/superset-ui-color/src/ColorSchemeRegistry.ts similarity index 52% rename from packages/superset-ui-color/src/ColorSchemeRegistry.js rename to packages/superset-ui-color/src/ColorSchemeRegistry.ts index 1877615cc733e..05cc7b6ad3c00 100644 --- a/packages/superset-ui-color/src/ColorSchemeRegistry.js +++ b/packages/superset-ui-color/src/ColorSchemeRegistry.ts @@ -1,10 +1,14 @@ import { RegistryWithDefaultKey } from '@superset-ui/core'; -export default class ColorSchemeRegistry extends RegistryWithDefaultKey { +export default class ColorSchemeRegistry extends RegistryWithDefaultKey { constructor() { super({ name: 'ColorScheme', setFirstItemAsDefault: true, }); } + + get(key?: string) { + return super.get(key) as T | undefined; + } } diff --git a/packages/superset-ui-color/src/SequentialScheme.js b/packages/superset-ui-color/src/SequentialScheme.ts similarity index 64% rename from packages/superset-ui-color/src/SequentialScheme.js rename to packages/superset-ui-color/src/SequentialScheme.ts index 95e0b8c1505c0..31cefd65c1689 100644 --- a/packages/superset-ui-color/src/SequentialScheme.js +++ b/packages/superset-ui-color/src/SequentialScheme.ts @@ -1,7 +1,7 @@ import { scaleLinear } from 'd3-scale'; -import ColorScheme from './ColorScheme'; +import ColorScheme, { ColorSchemeConfig } from './ColorScheme'; -function range(count) { +function range(count: number) { const values = []; for (let i = 0; i < count; i += 1) { values.push(i); @@ -10,14 +10,20 @@ function range(count) { return values; } +export interface SequentialSchemeConfig extends ColorSchemeConfig { + isDiverging?: boolean; +} + export default class SequentialScheme extends ColorScheme { - constructor(input) { - super(input); - const { isDiverging = false } = input; + isDiverging: boolean; + + constructor(config: SequentialSchemeConfig) { + super(config); + const { isDiverging = false } = config; this.isDiverging = isDiverging; } - createLinearScale(extent = [0, 1]) { + createLinearScale(extent: number[] = [0, 1]) { // Create matching domain // because D3 continuous scale uses piecewise mapping // between domain and range. @@ -25,13 +31,13 @@ export default class SequentialScheme extends ColorScheme { const denominator = this.colors.length - 1; const domain = range(this.colors.length).map(i => valueScale(i / denominator)); - return scaleLinear() + return scaleLinear() .domain(domain) .range(this.colors) .clamp(true); } - getColors(numColors = this.colors.length) { + getColors(numColors: number = this.colors.length): string[] { if (numColors === this.colors.length) { return this.colors; } diff --git a/packages/superset-ui-color/src/SequentialSchemeRegistrySingleton.js b/packages/superset-ui-color/src/SequentialSchemeRegistrySingleton.ts similarity index 60% rename from packages/superset-ui-color/src/SequentialSchemeRegistrySingleton.js rename to packages/superset-ui-color/src/SequentialSchemeRegistrySingleton.ts index c5951ef2f0898..648576067ba0a 100644 --- a/packages/superset-ui-color/src/SequentialSchemeRegistrySingleton.js +++ b/packages/superset-ui-color/src/SequentialSchemeRegistrySingleton.ts @@ -1,7 +1,8 @@ import { makeSingleton } from '@superset-ui/core'; import ColorSchemeRegistry from './ColorSchemeRegistry'; +import SequentialScheme from './SequentialScheme'; -class SequentialSchemeRegistry extends ColorSchemeRegistry {} +class SequentialSchemeRegistry extends ColorSchemeRegistry {} const getInstance = makeSingleton(SequentialSchemeRegistry); diff --git a/packages/superset-ui-color/src/colorSchemes/categorical/airbnb.js b/packages/superset-ui-color/src/colorSchemes/categorical/airbnb.ts similarity index 100% rename from packages/superset-ui-color/src/colorSchemes/categorical/airbnb.js rename to packages/superset-ui-color/src/colorSchemes/categorical/airbnb.ts diff --git a/packages/superset-ui-color/src/colorSchemes/categorical/d3.js b/packages/superset-ui-color/src/colorSchemes/categorical/d3.ts similarity index 100% rename from packages/superset-ui-color/src/colorSchemes/categorical/d3.js rename to packages/superset-ui-color/src/colorSchemes/categorical/d3.ts diff --git a/packages/superset-ui-color/src/colorSchemes/categorical/google.js b/packages/superset-ui-color/src/colorSchemes/categorical/google.ts similarity index 100% rename from packages/superset-ui-color/src/colorSchemes/categorical/google.js rename to packages/superset-ui-color/src/colorSchemes/categorical/google.ts diff --git a/packages/superset-ui-color/src/colorSchemes/categorical/lyft.js b/packages/superset-ui-color/src/colorSchemes/categorical/lyft.ts similarity index 100% rename from packages/superset-ui-color/src/colorSchemes/categorical/lyft.js rename to packages/superset-ui-color/src/colorSchemes/categorical/lyft.ts diff --git a/packages/superset-ui-color/src/colorSchemes/sequential/common.js b/packages/superset-ui-color/src/colorSchemes/sequential/common.ts similarity index 100% rename from packages/superset-ui-color/src/colorSchemes/sequential/common.js rename to packages/superset-ui-color/src/colorSchemes/sequential/common.ts diff --git a/packages/superset-ui-color/src/colorSchemes/sequential/d3.js b/packages/superset-ui-color/src/colorSchemes/sequential/d3.ts similarity index 100% rename from packages/superset-ui-color/src/colorSchemes/sequential/d3.js rename to packages/superset-ui-color/src/colorSchemes/sequential/d3.ts diff --git a/packages/superset-ui-color/src/index.js b/packages/superset-ui-color/src/index.ts similarity index 77% rename from packages/superset-ui-color/src/index.js rename to packages/superset-ui-color/src/index.ts index d778fa1510ac3..5bd259ec2fda8 100644 --- a/packages/superset-ui-color/src/index.js +++ b/packages/superset-ui-color/src/index.ts @@ -1,10 +1,11 @@ import * as CategoricalColorNamespace from './CategoricalColorNamespace'; export { CategoricalColorNamespace }; +export { ColorSchemeConfig } from './ColorScheme'; export { default as CategoricalColorScale } from './CategoricalColorScale'; export { default as CategoricalScheme } from './CategoricalScheme'; export { default as getCategoricalSchemeRegistry } from './CategoricalSchemeRegistrySingleton'; export { default as getSequentialSchemeRegistry } from './SequentialSchemeRegistrySingleton'; -export { default as SequentialScheme } from './SequentialScheme'; +export { default as SequentialScheme, SequentialSchemeConfig } from './SequentialScheme'; export const BRAND_COLOR = '#00A699'; diff --git a/packages/superset-ui-color/src/stringifyAndTrim.js b/packages/superset-ui-color/src/stringifyAndTrim.ts similarity index 57% rename from packages/superset-ui-color/src/stringifyAndTrim.js rename to packages/superset-ui-color/src/stringifyAndTrim.ts index 06e4d53b93b1b..8160c63dd7d2e 100644 --- a/packages/superset-ui-color/src/stringifyAndTrim.js +++ b/packages/superset-ui-color/src/stringifyAndTrim.ts @@ -2,6 +2,6 @@ * Ensure value is a string * @param {any} value */ -export default function stringifyAndTrim(value) { +export default function stringifyAndTrim(value?: number | string) { return String(value).trim(); } diff --git a/packages/superset-ui-color/src/types.ts b/packages/superset-ui-color/src/types.ts new file mode 100644 index 0000000000000..f1de7d07900d6 --- /dev/null +++ b/packages/superset-ui-color/src/types.ts @@ -0,0 +1,5 @@ +/* eslint-disable import/prefer-default-export */ + +export interface ColorsLookup { + [key: string]: string; +} diff --git a/packages/superset-ui-color/test/CategoricalColorNameSpace.test.js b/packages/superset-ui-color/test/CategoricalColorNameSpace.test.ts similarity index 94% rename from packages/superset-ui-color/test/CategoricalColorNameSpace.test.js rename to packages/superset-ui-color/test/CategoricalColorNameSpace.test.ts index c7d92ad33c05a..d5c1f6dd70fd2 100644 --- a/packages/superset-ui-color/test/CategoricalColorNameSpace.test.js +++ b/packages/superset-ui-color/test/CategoricalColorNameSpace.test.ts @@ -55,6 +55,13 @@ describe('CategoricalColorNamespace', () => { expect(scale).toBeDefined(); expect(scale.getColor('dog')).toBeDefined(); }); + it('returns a scale when a schemeId is not specified and there is no default key', () => { + getCategoricalSchemeRegistry().clearDefaultKey(); + const namespace = getNamespace('new-space'); + const scale = namespace.getScale(); + expect(scale).toBeDefined(); + getCategoricalSchemeRegistry().setDefaultKey('testColors'); + }); it('returns same scale if the scale with that name already exists in this namespace', () => { const namespace = getNamespace('test-get-scale2'); const scale1 = namespace.getScale('testColors'); diff --git a/packages/superset-ui-color/test/CategoricalColorScale.test.js b/packages/superset-ui-color/test/CategoricalColorScale.test.ts similarity index 98% rename from packages/superset-ui-color/test/CategoricalColorScale.test.js rename to packages/superset-ui-color/test/CategoricalColorScale.test.ts index 9581fdcb6305b..50ab63e11e03f 100644 --- a/packages/superset-ui-color/test/CategoricalColorScale.test.js +++ b/packages/superset-ui-color/test/CategoricalColorScale.test.ts @@ -40,7 +40,7 @@ describe('CategoricalColorScale', () => { expect(c3).not.toBe(c1); }); it('recycles colors when number of items exceed available colors', () => { - const colorSet = {}; + const colorSet: { [key: string]: number } = {}; const scale = new CategoricalColorScale(['blue', 'red', 'green']); const colors = [ scale.getColor('pig'), diff --git a/packages/superset-ui-color/test/ColorScheme.test.js b/packages/superset-ui-color/test/ColorScheme.test.ts similarity index 57% rename from packages/superset-ui-color/test/ColorScheme.test.js rename to packages/superset-ui-color/test/ColorScheme.test.ts index c400d55a50af5..3cf63c420c080 100644 --- a/packages/superset-ui-color/test/ColorScheme.test.js +++ b/packages/superset-ui-color/test/ColorScheme.test.ts @@ -2,11 +2,6 @@ import ColorScheme from '../src/ColorScheme'; describe('ColorScheme', () => { describe('new ColorScheme()', () => { - it('requires name and color', () => { - expect(() => new ColorScheme()).toThrow(); - expect(() => new ColorScheme({ id: 'test' })).toThrow(); - expect(() => new ColorScheme({ colors: ['red', 'blue'] })).toThrow(); - }); it('returns an instance of ColorScheme', () => { const scheme = new ColorScheme({ id: 'test', colors: ['red', 'blue'] }); expect(scheme).toBeInstanceOf(ColorScheme); diff --git a/packages/superset-ui-color/test/ColorSchemeRegistry.test.js b/packages/superset-ui-color/test/ColorSchemeRegistry.test.ts similarity index 100% rename from packages/superset-ui-color/test/ColorSchemeRegistry.test.js rename to packages/superset-ui-color/test/ColorSchemeRegistry.test.ts diff --git a/packages/superset-ui-color/test/SequentialScheme.test.js b/packages/superset-ui-color/test/SequentialScheme.test.ts similarity index 100% rename from packages/superset-ui-color/test/SequentialScheme.test.js rename to packages/superset-ui-color/test/SequentialScheme.test.ts diff --git a/packages/superset-ui-color/test/colorSchemes.test.js b/packages/superset-ui-color/test/colorSchemes.test.ts similarity index 100% rename from packages/superset-ui-color/test/colorSchemes.test.js rename to packages/superset-ui-color/test/colorSchemes.test.ts diff --git a/packages/superset-ui-color/test/index.test.js b/packages/superset-ui-color/test/index.test.ts similarity index 100% rename from packages/superset-ui-color/test/index.test.js rename to packages/superset-ui-color/test/index.test.ts diff --git a/packages/superset-ui-core/src/utils/isRequired.ts b/packages/superset-ui-core/src/utils/isRequired.ts index 2bcc4750cecfe..6a81534038993 100644 --- a/packages/superset-ui-core/src/utils/isRequired.ts +++ b/packages/superset-ui-core/src/utils/isRequired.ts @@ -1,3 +1,3 @@ -export default function isRequired(field: string) { +export default function isRequired(field: string): never { throw new Error(`${field} is required.`); }