From b1086b66148d860e9adfcefee73c265e68098de5 Mon Sep 17 00:00:00 2001 From: Thanh Ngo Date: Thu, 3 May 2018 12:48:03 -0400 Subject: [PATCH] add type definition for idyll-document (#25455) --- types/idyll-document/idyll-document-tests.ts | 5 ++ types/idyll-document/index.d.ts | 62 ++++++++++++++++++++ types/idyll-document/tsconfig.json | 16 +++++ types/idyll-document/tslint.json | 3 + 4 files changed, 86 insertions(+) create mode 100644 types/idyll-document/idyll-document-tests.ts create mode 100644 types/idyll-document/index.d.ts create mode 100644 types/idyll-document/tsconfig.json create mode 100644 types/idyll-document/tslint.json diff --git a/types/idyll-document/idyll-document-tests.ts b/types/idyll-document/idyll-document-tests.ts new file mode 100644 index 0000000000..880e017013 --- /dev/null +++ b/types/idyll-document/idyll-document-tests.ts @@ -0,0 +1,5 @@ +import IdyllDocument, { IdyllDocumentProps } from "idyll-document"; +import { createElement } from "react"; + +// $ExpectType ReactElement +createElement(IdyllDocument); diff --git a/types/idyll-document/index.d.ts b/types/idyll-document/index.d.ts new file mode 100644 index 0000000000..47ba1f7845 --- /dev/null +++ b/types/idyll-document/index.d.ts @@ -0,0 +1,62 @@ +// Type definitions for idyll-document 2.9 +// Project: https://github.com/idyll-lang/idyll/tree/master/packages/idyll-document +// Definitions by: Thanh Ngo +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import { PureComponent, ReactType } from "react"; +import { Options as CompilerOptions, AST } from "idyll-compiler"; + +export interface IdyllDocumentProps { + /** + * Components to be rendered with + */ + components: any; + /** + * the AST to be rendered on the page + * If provided, this will be used insteaed of + * the markup + */ + ast?: AST; + /** + * The Idyll markup to be compiled into AST + */ + markup?: string; + /** + * Initial data set + */ + datasets?: object; + + /** + * The theme for idyll document + * Will correspond to one theme in idyll-theme package + */ + theme?: string; + /** + * The layout for idyll document + * Will correspond to one one layout in idyll-layouts package + */ + layout?: string; + /** + * Callback function if error happens during compilation + */ + onError?: (err: Error) => void; + /** + * The React component rendered when an error occurs + */ + errorComponent?: ReactType<{ + className?: string; + children: Error["message"] | null; + }>; + /** + * Compiler option for Idyll compiler when compiling markup + */ + compilerOptions?: CompilerOptions; + + context?: (context: any) => void; + initialState?: any; +} + +declare class IdyllDocument extends PureComponent {} + +export default IdyllDocument; diff --git a/types/idyll-document/tsconfig.json b/types/idyll-document/tsconfig.json new file mode 100644 index 0000000000..6e3da4c990 --- /dev/null +++ b/types/idyll-document/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "strictFunctionTypes": true + }, + "files": ["index.d.ts", "idyll-document-tests.ts"] +} diff --git a/types/idyll-document/tslint.json b/types/idyll-document/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/idyll-document/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}