From 1cde5fd4bed85380a1fcf88d5bfced87e82c5622 Mon Sep 17 00:00:00 2001 From: Pete Date: Thu, 14 Feb 2019 21:59:35 -0800 Subject: [PATCH 1/4] Allow arbitrary strings in string literal union types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Restore `Transform` and `ValueTransform` string union literal types • Use generics to allow arbitrary strings for parameters with the previously listed types • Move exported functions to the bottom of the file --- types/theo/index.d.ts | 133 +++++++++++++++++++++++------------------- 1 file changed, 72 insertions(+), 61 deletions(-) diff --git a/types/theo/index.d.ts b/types/theo/index.d.ts index d60a797159..27ee6c51c0 100644 --- a/types/theo/index.d.ts +++ b/types/theo/index.d.ts @@ -5,51 +5,46 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 -import { Collection, Map, List, OrderedMap } from "immutable"; +import { Collection, Map, List, OrderedMap } from 'immutable' export type StyleProperty = - | "name" - | "value" - | "type" - | "originalValue" - | "category" - | "comment" - | "meta"; + | 'name' + | 'value' + | 'type' + | 'originalValue' + | 'category' + | 'comment' + | 'meta'; export type Format = - | "custom-properties.css" - | "cssmodules.css" - | "scss" - | "sass" - | "less" - | "styl" - | "map.css" - | "map.variable.scss" - | "list.scss" - | "module.js" - | "common.js" - | "html" - | "json" - | "raw.json" - | "ios.json" - | "android.xml" - | "aura.tokens"; + | 'custom-properties.css' + | 'cssmodules.css' + | 'scss' + | 'sass' + | 'less' + | 'styl' + | 'map.css' + | 'map.variable.scss' + | 'list.scss' + | 'module.js' + | 'common.js' + | 'html' + | 'json' + | 'raw.json' + | 'ios.json' + | 'android.xml' + | 'aura.tokens'; -export function convert(options: ConvertOptions): Promise; -export function convertSync(options: ConvertOptions): string; -export function registerFormat( - name: string, - format: FormatResultFn | string -): void; -export function registerTransform( - name: string, - valueTransforms: string[] -): void; -export function registerValueTransform( - name: string, - predicate: (prop: Prop) => boolean, - transform: (prop: Prop) => string | number -): void; +export type Transform = 'raw' | 'ios' | 'android' | 'web'; + +export type ValueTransform = + | 'color/rgb' + | 'color/hex' + | 'color/hex8rgba' + | 'color/hex8argb' + | 'percentage/float' + | 'relative/pixel' + | 'relative/pixelValue'; export type Prop = Map; export type Props = List; @@ -58,36 +53,52 @@ export type Meta = Map; export type FormatResultFn = (result: ImmutableStyleMap) => string; export interface StyleMap { - aliases: Aliases; - global?: Props; - imports?: string[]; - props: Props; - meta: Meta; - options: object; + aliases: Aliases; + global?: Props; + imports?: string[]; + props: Props; + meta: Meta; + options: object; } export interface ImmutableStyleMap extends Map { - toJS(): StyleMap; - get(key: K): StyleMap[K]; + toJS(): StyleMap; + get(key: K): StyleMap[K]; } export interface ConvertOptions { - transform: TransformOptions; - format: FormatOptions; - resolveAliases?: boolean; - resolveMetaAliases?: boolean; + transform: TransformOptions; + format: FormatOptions; + resolveAliases?: boolean; + resolveMetaAliases?: boolean; } -export interface TransformOptions { - type?: string; - file: string; - data?: string; +export interface TransformOptions { + type?: Transform | T; + file: string; + data?: string; } export interface FormatOptions { - type: Format; - options?: ( - options: object, - transformPropName?: (name: string) => string - ) => void; + type: Format; + options?: ( + options: object, + transformPropName?: (name: string) => string + ) => void; } + +export function convert(options: ConvertOptions): Promise; +export function convertSync(options: ConvertOptions): string; +export function registerFormat( + name: Format | T, + format: FormatResultFn | string +): void; +export function registerTransform( + name: Transform | T, + valueTransforms: ValueTransform[] | T[] +): void; +export function registerValueTransform( + name: ValueTransform | T, + predicate: (prop: Prop) => boolean, + transform: (prop: Prop) => string | number +): void; From b9c1d04fefc27a7e2d433a9739b0e2b355c58316 Mon Sep 17 00:00:00 2001 From: Pete Date: Thu, 14 Feb 2019 22:05:14 -0800 Subject: [PATCH 2/4] Undo prettier formatting and fix type argument error --- types/theo/index.d.ts | 128 +++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/types/theo/index.d.ts b/types/theo/index.d.ts index 27ee6c51c0..3735da3e0c 100644 --- a/types/theo/index.d.ts +++ b/types/theo/index.d.ts @@ -5,46 +5,46 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 -import { Collection, Map, List, OrderedMap } from 'immutable' +import { Collection, Map, List, OrderedMap } from "immutable"; export type StyleProperty = - | 'name' - | 'value' - | 'type' - | 'originalValue' - | 'category' - | 'comment' - | 'meta'; + | "name" + | "value" + | "type" + | "originalValue" + | "category" + | "comment" + | "meta"; export type Format = - | 'custom-properties.css' - | 'cssmodules.css' - | 'scss' - | 'sass' - | 'less' - | 'styl' - | 'map.css' - | 'map.variable.scss' - | 'list.scss' - | 'module.js' - | 'common.js' - | 'html' - | 'json' - | 'raw.json' - | 'ios.json' - | 'android.xml' - | 'aura.tokens'; + | "custom-properties.css" + | "cssmodules.css" + | "scss" + | "sass" + | "less" + | "styl" + | "map.css" + | "map.variable.scss" + | "list.scss" + | "module.js" + | "common.js" + | "html" + | "json" + | "raw.json" + | "ios.json" + | "android.xml" + | "aura.tokens"; -export type Transform = 'raw' | 'ios' | 'android' | 'web'; +export type Transform = "raw" | "ios" | "android" | "web"; export type ValueTransform = - | 'color/rgb' - | 'color/hex' - | 'color/hex8rgba' - | 'color/hex8argb' - | 'percentage/float' - | 'relative/pixel' - | 'relative/pixelValue'; + | "color/rgb" + | "color/hex" + | "color/hex8rgba" + | "color/hex8argb" + | "percentage/float" + | "relative/pixel" + | "relative/pixelValue"; export type Prop = Map; export type Props = List; @@ -53,52 +53,52 @@ export type Meta = Map; export type FormatResultFn = (result: ImmutableStyleMap) => string; export interface StyleMap { - aliases: Aliases; - global?: Props; - imports?: string[]; - props: Props; - meta: Meta; - options: object; + aliases: Aliases; + global?: Props; + imports?: string[]; + props: Props; + meta: Meta; + options: object; } export interface ImmutableStyleMap extends Map { - toJS(): StyleMap; - get(key: K): StyleMap[K]; + toJS(): StyleMap; + get(key: K): StyleMap[K]; } export interface ConvertOptions { - transform: TransformOptions; - format: FormatOptions; - resolveAliases?: boolean; - resolveMetaAliases?: boolean; + transform: TransformOptions; + format: FormatOptions; + resolveAliases?: boolean; + resolveMetaAliases?: boolean; } -export interface TransformOptions { - type?: Transform | T; - file: string; - data?: string; +export interface TransformOptions { + type?: Transform | T; + file: string; + data?: string; } export interface FormatOptions { - type: Format; - options?: ( - options: object, - transformPropName?: (name: string) => string - ) => void; + type: Format; + options?: ( + options: object, + transformPropName?: (name: string) => string + ) => void; } export function convert(options: ConvertOptions): Promise; export function convertSync(options: ConvertOptions): string; -export function registerFormat( - name: Format | T, - format: FormatResultFn | string +export function registerFormat( + name: Format | T, + format: FormatResultFn | string ): void; -export function registerTransform( - name: Transform | T, - valueTransforms: ValueTransform[] | T[] +export function registerTransform( + name: Transform | T, + valueTransforms: ValueTransform[] | T[] ): void; -export function registerValueTransform( - name: ValueTransform | T, - predicate: (prop: Prop) => boolean, - transform: (prop: Prop) => string | number +export function registerValueTransform( + name: ValueTransform | T, + predicate: (prop: Prop) => boolean, + transform: (prop: Prop) => string | number ): void; From ac4cae1d50f4c974b26d74f4a5a5b8e43a3c057e Mon Sep 17 00:00:00 2001 From: Pete Date: Fri, 15 Feb 2019 08:24:46 -0800 Subject: [PATCH 3/4] Bump TS to 2.3 --- types/theo/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/theo/index.d.ts b/types/theo/index.d.ts index 3735da3e0c..de15c0238a 100644 --- a/types/theo/index.d.ts +++ b/types/theo/index.d.ts @@ -1,9 +1,9 @@ -// Type definitions for theo 8.1 +// Type definitions for Theo 8.1 // Project: https://github.com/salesforce-ux/theo // Definitions by: Pete Petrash // Niko Laitinen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.2 +// TypeScript Version: 2.3 import { Collection, Map, List, OrderedMap } from "immutable"; From f3e63b2691452497c99b213e84e20eb43803f849 Mon Sep 17 00:00:00 2001 From: Pete Date: Fri, 15 Feb 2019 10:57:30 -0800 Subject: [PATCH 4/4] Disable 'no-unnecessary-generics' rule --- types/theo/tslint.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/types/theo/tslint.json b/types/theo/tslint.json index 3db14f85ea..71ee04c4e1 100644 --- a/types/theo/tslint.json +++ b/types/theo/tslint.json @@ -1 +1,6 @@ -{ "extends": "dtslint/dt.json" } +{ + "extends": "dtslint/dt.json", + "rules": { + "no-unnecessary-generics": false + } +}