From 1cde5fd4bed85380a1fcf88d5bfced87e82c5622 Mon Sep 17 00:00:00 2001 From: Pete Date: Thu, 14 Feb 2019 21:59:35 -0800 Subject: [PATCH] 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;