From 2b9558d869801e3af89fa9b9490c93e2fce2750e Mon Sep 17 00:00:00 2001 From: Boye Borg Date: Tue, 11 Sep 2018 01:10:37 +0200 Subject: [PATCH] Type definitions for "typography.js" (#28625) * autogenerate files * add strictFunctionTypes * create type definitions for typography.js * add type tests * use pascal case instead of camel case --- types/typography/index.d.ts | 60 ++++++++++++++++++++++++++++ types/typography/tsconfig.json | 23 +++++++++++ types/typography/tslint.json | 1 + types/typography/typography-tests.ts | 12 ++++++ 4 files changed, 96 insertions(+) create mode 100644 types/typography/index.d.ts create mode 100644 types/typography/tsconfig.json create mode 100644 types/typography/tslint.json create mode 100644 types/typography/typography-tests.ts diff --git a/types/typography/index.d.ts b/types/typography/index.d.ts new file mode 100644 index 0000000000..2c5be43583 --- /dev/null +++ b/types/typography/index.d.ts @@ -0,0 +1,60 @@ +// Type definitions for typography 0.16 +// Project: https://github.com/KyleAMathews/typography.js +// Definitions by: Boye +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +interface BaseLine { + fontSize: string; + lineHeight: string; +} + +export interface VerticalRhythm { + rhythm: (value: number) => string; + scale: (value: number) => object; + adjustFontSizeTo: (value?: number | string) => object; + linesForFontSize: (fontSize: number) => number; + establishBaseline: () => BaseLine; +} + +export interface GoogleFont { + name: string; + styles: string[]; +} + +export interface TypographyOptions { + baseFontSize?: string; + baseLineHeight?: number; + scaleRatio?: number; + googleFonts?: GoogleFont[]; + headerFontFamily?: string[]; + bodyFontFamily?: string[]; + headerColor?: string; + bodyColor?: string; + headerWeight?: number | string; + bodyWeight?: number | string; + boldWeight?: number | string; + blockMarginBottom?: number; + includeNormalize?: boolean; + overrideStyles?: ( + VerticalRhythm: VerticalRhythm, + options: TypographyOptions, + styles: any + ) => object; + overrideThemeStyles?: ( + VerticalRhythm: VerticalRhythm, + options: TypographyOptions, + styles: any + ) => object; + plugins?: any[]; +} + +declare class Typography { + constructor(opts: TypographyOptions); + options: TypographyOptions; + createStyles(): string; + toJSON(): object; + injectStyles(): void; +} + +export default Typography; diff --git a/types/typography/tsconfig.json b/types/typography/tsconfig.json new file mode 100644 index 0000000000..cebfdd1e2b --- /dev/null +++ b/types/typography/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "typography-tests.ts" + ] +} diff --git a/types/typography/tslint.json b/types/typography/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/typography/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/typography/typography-tests.ts b/types/typography/typography-tests.ts new file mode 100644 index 0000000000..5b004d2eae --- /dev/null +++ b/types/typography/typography-tests.ts @@ -0,0 +1,12 @@ +import Typography from 'typography'; + +const typography = new Typography({ + baseFontSize: '18px', + baseLineHeight: 1.45, + headerFontFamily: ['Avenir Next', 'Helvetica Neue', 'Segoe UI', 'Helvetica', 'Arial', 'sans-serif'], + bodyFontFamily: ['Georgia', 'serif'] +}); + +typography.createStyles(); // $ExpectType string +typography.toJSON(); // $ExpectType object +typography.options; // $ExpectType TypographyOptions