Add prismic-dom types for version 2.1 (#34228)

* Add prismic-dom new asHtml types

* improve indentation
This commit is contained in:
Douglas Nomizo 2019-03-27 20:08:26 -03:00 committed by Ron Buckton
parent f1be41efc5
commit f7fa09cecb
2 changed files with 50 additions and 5 deletions

View File

@ -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 <https://github.com/nickw444>
// Siggy Bilstein <https://github.com/sbilstein>
// Douglas Nomizo <https://github.com/douglasnomizo>
// 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<T> = (
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>,
): 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<string>;
declare const _default: {
RichText: RichText;
Link: Link
};
declare const _default: { RichText: RichText, Link: Link };
export default _default;

View File

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