Skip to content
Myr

fix(jsx): declare types for JSX correctly (#901)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Yusuke Wada · committed by GitHub · parent 6d8bd62 · Browse files · 2 files+16 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+16 added−8 removed

  • other:+16 added−8 removed

2 files+16 added−8 removed

modified:deno_dist/middleware/jsx/index.ts+8 added-4 removed
1import { escapeToBuffer } from '../../utils/html.ts'2import type { StringBuffer, HtmlEscaped, HtmlEscapedString } from '../../utils/html.ts'34// eslint-disable-next-line @typescript-eslint/no-explicit-any5type Props = Record<string, any>;5type Props = Record<string, any>67declare global {8 // eslint-disable-next-line @typescript-eslint/no-namespace9 namespace jsx.JSX {9 namespace JSX {10 type Element = HtmlEscapedString11 interface IntrinsicElements {11 [tagName: string]: Props,12 [tagName: string]: Props13 }14 }15}16
50 unmodified lines
67 } else if (typeof child === 'boolean' || child === null || child === undefined) {68 continue69 } else if (child instanceof JSXNode) {70 child.toStringToBuffer(buffer)70 } else if (typeof child === 'number' || (child as unknown as { isEscaped: boolean }).isEscaped) {71 } else if (72 typeof child === 'number' ||73 (child as unknown as { isEscaped: boolean }).isEscaped74 ) {75 buffer[0] += child76 } else {77 // `child` type is `Child[]`, so stringify recursively78 childrenToStringToBuffer(child, buffer)
151 unmodified lines
modified:src/middleware/jsx/index.ts+8 added-4 removed
1import { escapeToBuffer } from '../../utils/html'2import type { StringBuffer, HtmlEscaped, HtmlEscapedString } from '../../utils/html'34// eslint-disable-next-line @typescript-eslint/no-explicit-any5type Props = Record<string, any>;5type Props = Record<string, any>67declare global {8 // eslint-disable-next-line @typescript-eslint/no-namespace9 namespace jsx.JSX {9 namespace JSX {10 type Element = HtmlEscapedString11 interface IntrinsicElements {11 [tagName: string]: Props,12 [tagName: string]: Props13 }14 }15}16
50 unmodified lines
67 } else if (typeof child === 'boolean' || child === null || child === undefined) {68 continue69 } else if (child instanceof JSXNode) {70 child.toStringToBuffer(buffer)70 } else if (typeof child === 'number' || (child as unknown as { isEscaped: boolean }).isEscaped) {71 } else if (72 typeof child === 'number' ||73 (child as unknown as { isEscaped: boolean }).isEscaped74 ) {75 buffer[0] += child76 } else {77 // `child` type is `Child[]`, so stringify recursively78 childrenToStringToBuffer(child, buffer)
151 unmodified lines