Skip to content

Commit cb3dd6f

Browse files
leo-arjrf0110
authored andcommitted
Require at least one method for 'ElementHandler'
Taken from the answer given by https://stackoverflow.com/users/2077574/kpd in https://stackoverflow.com/a/49725198
1 parent 56a4b77 commit cb3dd6f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

index.d.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ interface Doctype {
307307
readonly systemId: string | null
308308
}
309309

310-
interface ElementHandler {
310+
interface ElementHandlerOptionals {
311311
/**
312312
* An incoming element, such as `div`
313313
*/
@@ -322,6 +322,15 @@ interface ElementHandler {
322322
text?(text: Text): void
323323
}
324324

325+
// See https://stackoverflow.com/a/49725198
326+
type RequireAtLeastOne<T, Keys extends keyof T = keyof T> =
327+
Pick<T, Exclude<keyof T, Keys>>
328+
& {
329+
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>
330+
}[Keys]
331+
332+
type ElementHandler = RequireAtLeastOne<ElementHandlerOptionals, 'element' | 'comments' | 'text'>
333+
325334
interface DocumentHandler {
326335
/**
327336
* An incoming doctype, such as <!DOCTYPE html>

0 commit comments

Comments
 (0)