From 6b910c77852fae05e1bb8324ee0c399d0cd5105b Mon Sep 17 00:00:00 2001 From: Eric Taylor Date: Tue, 14 May 2019 11:59:09 -0600 Subject: [PATCH] Add styletron-standard types (#35324) * add styletron-standard types * fix StyleObject type to accept nested StyleObject type * use csstype package --- types/styletron-standard/index.d.ts | 39 +++++++++++++++++++ types/styletron-standard/package.json | 6 +++ .../styletron-standard-tests.ts | 34 ++++++++++++++++ types/styletron-standard/tsconfig.json | 16 ++++++++ types/styletron-standard/tslint.json | 1 + 5 files changed, 96 insertions(+) create mode 100644 types/styletron-standard/index.d.ts create mode 100644 types/styletron-standard/package.json create mode 100644 types/styletron-standard/styletron-standard-tests.ts create mode 100644 types/styletron-standard/tsconfig.json create mode 100644 types/styletron-standard/tslint.json diff --git a/types/styletron-standard/index.d.ts b/types/styletron-standard/index.d.ts new file mode 100644 index 0000000000..e61c090178 --- /dev/null +++ b/types/styletron-standard/index.d.ts @@ -0,0 +1,39 @@ +// Type definitions for styletron-standard 2.0 +// Project: https://github.com/styletron/styletron +// Definitions by: Eric Taylor +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.9 + +import * as CSS from 'csstype'; + +export type Properties = CSS.Properties; +export type FontFace = CSS.FontFace; +export interface KeyframesPercentageObject { + [key: string]: Properties; +} + +export type KeyframesObject = KeyframesPercentageObject & { + from?: Properties; + to?: Properties; +}; + +// Unrecognized properties are assumed to be media queries +// or pseudo selectors w/ nested style objects. +// See: https://github.com/styletron/styletron-standard +export type StyleObject = Properties & + { [key in string]: Properties[keyof Properties] | StyleObject }; + +export interface StandardEngine { + renderStyle(style: StyleObject): string; + renderKeyframes(keyframes: KeyframesObject): string; + renderFontFace(fontFace: FontFace): string; +} + +export function driver(style: StyleObject, styletron: StandardEngine): string; + +export function getInitialStyle(): StyleObject; + +export function renderDeclarativeRules( + style: StyleObject, + styletrong: StandardEngine +): StyleObject; diff --git a/types/styletron-standard/package.json b/types/styletron-standard/package.json new file mode 100644 index 0000000000..5458316151 --- /dev/null +++ b/types/styletron-standard/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "csstype": "^2.6.4" + } +} diff --git a/types/styletron-standard/styletron-standard-tests.ts b/types/styletron-standard/styletron-standard-tests.ts new file mode 100644 index 0000000000..b8b0b44969 --- /dev/null +++ b/types/styletron-standard/styletron-standard-tests.ts @@ -0,0 +1,34 @@ +import { + driver, + getInitialStyle, + renderDeclarativeRules, + StyleObject, + StandardEngine, + KeyframesObject, + FontFace, +} from 'styletron-standard'; + +const validStyleObject: StyleObject = { + display: 'block', + ':after': { + content: '" "', + }, +}; + +const renderStyle = (style: StyleObject) => 'style'; +const renderKeyframes = (keyframes: KeyframesObject) => 'keyframes'; +const renderFontFace = (fontFace: FontFace) => 'font-face'; + +const engine: StandardEngine = { + renderStyle, + renderKeyframes, + renderFontFace, +}; + +// driver tests +driver(validStyleObject, engine); // $ExpectType string +driver(getInitialStyle(), engine); // $ExpectType string + +// renderDeclarativeRules tests +renderDeclarativeRules(getInitialStyle(), engine); // $ExpectType StyleObject +renderDeclarativeRules(validStyleObject, engine); // $ExpectType StyleObject diff --git a/types/styletron-standard/tsconfig.json b/types/styletron-standard/tsconfig.json new file mode 100644 index 0000000000..ddddd09aac --- /dev/null +++ b/types/styletron-standard/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "styletron-standard-tests.ts"] +} diff --git a/types/styletron-standard/tslint.json b/types/styletron-standard/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/styletron-standard/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }