Add typing for children of react-document-title (#43022)

* Add typing for children of react-document-title

react-document-title uses React.Children.only to get the only child, and raises an error if more than one child is passed.

https://github.com/gaearon/react-document-title/blob/master/index.js#L31

* Add a test case with a child

* Turns out it should be React.ReactChild

Turns out it should be React.ReactChild

* Fix typo
This commit is contained in:
Michael Rochlin 2020-03-22 17:28:19 -04:00 committed by GitHub
parent 3ac9608f05
commit 31dadd46f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import * as React from 'react';
interface DocumentTitleProps {
title: string;
children?: React.ReactChild | null;
}
declare class DocumentTitle extends React.Component<DocumentTitleProps, any> {

View File

@ -6,3 +6,15 @@ class TitleTest extends React.Component<any, any> {
return <DocumentTitle title="Test" />;
}
}
class TitleTestOneChild extends React.Component<any, any> {
render() {
return <DocumentTitle title="Test">A Child</DocumentTitle>;
}
}
class TitleTestOneReactChild extends React.Component<any, any> {
render() {
return <DocumentTitle title="Test"><div>A Child</div></DocumentTitle>;
}
}