Skip to content

Commit

Permalink
Merge pull request DefinitelyTyped#33332 from petekp/patch-2
Browse files Browse the repository at this point in the history
[Theo]: Fix registerTransform generic typing error
  • Loading branch information
amcasey authored Feb 23, 2019
2 parents ca7a196 + a9193f4 commit 6704f91
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
8 changes: 4 additions & 4 deletions types/theo/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ export function registerFormat<T extends string = never>(
name: Format | T,
format: FormatResultFn | string
): void;
export function registerTransform<T extends string = never>(
name: Transform | T,
valueTransforms: ValueTransform[] | T[]
): void;
export function registerTransform<
T extends string = never,
V extends string = never
>(name: Transform | T, valueTransforms: ValueTransform[] | V[]): void;
export function registerValueTransform<T extends string = never>(
name: ValueTransform | T,
predicate: (prop: Prop) => boolean,
Expand Down
33 changes: 33 additions & 0 deletions types/theo/theo-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,38 @@ theo.convert({
}
});

theo.convertSync({
transform: {
type: "raw",
file: "file",
data: "data"
},
format: {
type: "custom-properties.css"
}
});

// Register a provided transform with a provided value transform
theo.registerTransform("web", ["color/hex"]);

// Register a provided transform with custom value transform
theo.registerTransform("web", ["relative/pixelValue"]);

// Register a custom transform with custom value transform
theo.registerTransform("custom", ["relative/pixelValue"]);

// Register a custom transform with provided value transform
theo.registerTransform("custom", ["color/rgb"]);

// Register custom formatting function for a provided format
theo.registerFormat(
"cssmodules.css",
`{{#each props as |prop|}}
@value {{camelcase prop.category}}{{pascalcase prop.name}}: {{prop.value}};
{{/each}}`
);

// Register a custom value transform
theo.registerValueTransform(
"relative/pixelValue",
prop => prop.get("category") === "sizing",
Expand All @@ -28,3 +51,13 @@ theo.registerValueTransform(
return parseFloat(value.replace(/rem/g, "")) * 16;
}
);

// Override a custom value transform
theo.registerValueTransform(
"relative/pixel",
prop => prop.get("category") === "sizing",
prop => {
const value = prop.get("value").toString();
return `${parseFloat(value.replace(/rem/g, "")) * 16}px`;
}
);

0 comments on commit 6704f91

Please sign in to comment.