diff --git a/types/prismic-dom/index.d.ts b/types/prismic-dom/index.d.ts index 56536895f2..955ba79d04 100644 --- a/types/prismic-dom/index.d.ts +++ b/types/prismic-dom/index.d.ts @@ -1,12 +1,50 @@ -// Type definitions for prismic-dom 2.0 +// Type definitions for prismic-dom 2.1 // Project: https://github.com/prismicio/prismic-dom#readme // Definitions by: Nick Whyte // Siggy Bilstein +// Douglas Nomizo // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +type ElementType = + | "heading1" + | "heading2" + | "heading3" + | "heading4" + | "heading5" + | "heading6" + | "paragraph" + | "preformatted" + | "strong" + | "em" + | "list-item" + | "o-list-item" + | "group-list-item" + | "group-o-list-item" + | "image" + | "embed" + | "hyperlink" + | "label" + | "span"; + +type Elements = {[key in ElementType]: string}; + +type HTMLSerializer = ( + type: ElementType, + element: any, + text: string | null, + children: T[], + index: number, +) => T; interface RichText { - asHtml(richText: any, linkResolver?: (doc: any) => string): string; - asText(richText: any, joinString?: string): string; + asHtml( + richText: any, + linkResolver?: (doc: any) => string, + serializer?: HTMLSerializer, + ): string; + asText(richText: any, joinString?: string): string; + Elements: Elements; } interface Link { @@ -15,6 +53,11 @@ interface Link { export const RichText: RichText; export const Link: Link; +export const HTMLSerializer: HTMLSerializer; + +declare const _default: { + RichText: RichText; + Link: Link +}; -declare const _default: { RichText: RichText, Link: Link }; export default _default; diff --git a/types/prismic-dom/prismic-dom-tests.ts b/types/prismic-dom/prismic-dom-tests.ts index 598573cced..3975113e20 100644 --- a/types/prismic-dom/prismic-dom-tests.ts +++ b/types/prismic-dom/prismic-dom-tests.ts @@ -1,3 +1,5 @@ import prismicDom = require("prismic-dom"); -const rendered: string = prismicDom.RichText.asHtml({}); +const string = ''; +const rendered: string = prismicDom.RichText.asHtml({}, () => string, () => string); +const link: string = prismicDom.Link.url({}, ({}) => string);