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
This commit is contained in:
Boye Borg
2018-09-11 01:10:37 +02:00
committed by Ryan Cavanaugh
parent a60fadd782
commit 2b9558d869
4 changed files with 96 additions and 0 deletions

60
types/typography/index.d.ts vendored Normal file
View File

@@ -0,0 +1,60 @@
// Type definitions for typography 0.16
// Project: https://github.com/KyleAMathews/typography.js
// Definitions by: Boye <https://github.com/boyeborg>
// 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;

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

View File

@@ -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