diff --git a/types/Platform.d.ts b/types/Platform.d.ts index 68d268e4f..f728420ae 100644 --- a/types/Platform.d.ts +++ b/types/Platform.d.ts @@ -14,7 +14,7 @@ import { Options } from './Options'; import { File } from './File'; -export interface Platform { +export type Platform> = { transformGroup?: string; transforms?: string[]; basePxFontSize?: number; @@ -23,4 +23,4 @@ export interface Platform { files?: File[]; actions?: string[]; options?: Options; -} \ No newline at end of file +} & PlatformType; \ No newline at end of file diff --git a/types/Transform.d.ts b/types/Transform.d.ts index ea0886651..67bd11fa3 100644 --- a/types/Transform.d.ts +++ b/types/Transform.d.ts @@ -15,32 +15,35 @@ import { Matcher } from './Matcher'; import { TransformedToken } from './TransformedToken'; import { Platform } from './Platform'; -export interface NameTransform { +export interface NameTransform> { type: "name"; matcher?: Matcher; transformer: ( token: TransformedToken, - options?: Platform + options: Platform ) => string; } -export interface ValueTransform { +export interface ValueTransform> { type: "value"; transitive?: boolean; matcher?: Matcher; transformer: ( token: TransformedToken, - options?: Platform + options: Platform ) => any; } -export interface AttributeTransform { +export interface AttributeTransform> { type: "attribute"; matcher?: Matcher; transformer: ( token: TransformedToken, - options?: Platform + options: Platform ) => { [key: string]: any }; } -export type Transform = NameTransform | ValueTransform | AttributeTransform; \ No newline at end of file +export type Transform> = + | NameTransform + | ValueTransform + | AttributeTransform; \ No newline at end of file diff --git a/types/index.d.ts b/types/index.d.ts index 8e8968358..b5cee1d60 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -49,8 +49,8 @@ declare namespace StyleDictionary { type Matcher = _Matcher; type Options = _Options; type Parser = _Parser; - type Platform = _Platform; - type Transform = _Transform; + type Platform> = _Platform; + type Transform> = _Transform; type TransformedToken = _TransformedToken; type TransformedTokens = _TransformedTokens; type TransformGroup = _TransformGroup; @@ -97,7 +97,7 @@ declare namespace StyleDictionary { * }); * ``` */ - registerTransform(transform: Named): this; + registerTransform(transform: Named>): this; /** * Add a custom transformGroup to the Style Dictionary, which is a diff --git a/types/index.test-d.ts b/types/index.test-d.ts index b507c5d08..2c6743756 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -101,6 +101,29 @@ expectType( }) ); +type CustomPlatform = { + colorMode: 'light' | 'dark'; +} + +expectType( + StyleDictionary.registerTransform({ + name: "colormode", + type: "value", + matcher: function (token) { + return token.attributes?.category === "color"; + }, + transformer: function (token, platform) { + expectType(token); + expectType>(platform); + if (platform.colorMode === 'light') { + return 'light' + } else { + return 'dark' + } + }, + }) +); + expectType( StyleDictionary.registerTransformGroup({ name: "Swift", @@ -154,6 +177,12 @@ expectAssignable({ transforms: [`attribute/cti`], }); +expectAssignable({ + colorMode: 'dark', + files: [], + transformGroup: 'scss', +}); + expectAssignable({ transforms: [`attribute/cti`], files: [{