Add missing type definitions

This commit is contained in:
Leonid Logvinov
2018-05-11 17:38:51 +02:00
parent 6aed4fb1ae
commit b74957acdf
153 changed files with 655 additions and 600 deletions

View File

@@ -31,7 +31,7 @@ export class Badge extends React.Component<BadgeProps, BadgeState> {
isHovering: false,
};
}
public render() {
public render(): React.ReactNode {
const badgeStyle = {
...styles.badge,
backgroundColor: this.props.backgroundColor,
@@ -48,7 +48,7 @@ export class Badge extends React.Component<BadgeProps, BadgeState> {
</div>
);
}
private _setHoverState(isHovering: boolean) {
private _setHoverState(isHovering: boolean): void {
this.setState({
isHovering,
});

View File

@@ -14,7 +14,7 @@ export interface CustomEnumProps {
// This component renders custom string enums that was a work-around for versions of
// TypeScript <2.4.0 that did not support them natively. We keep it around to support
// older versions of 0x.js <0.9.0
export function CustomEnum(props: CustomEnumProps) {
export const CustomEnum = (props: CustomEnumProps) => {
const type = props.type;
if (!_.startsWith(type.defaultValue, STRING_ENUM_CODE_PREFIX)) {
logUtils.log('We do not yet support `Variable` types that are not strEnums');
@@ -31,4 +31,4 @@ export function CustomEnum(props: CustomEnumProps) {
{`}`}
</span>
);
}
};

View File

@@ -71,19 +71,19 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
isHoveringSidebar: false,
};
}
public componentDidMount() {
public componentDidMount(): void {
window.addEventListener('hashchange', this._onHashChanged.bind(this), false);
}
public componentWillUnmount() {
public componentWillUnmount(): void {
window.removeEventListener('hashchange', this._onHashChanged.bind(this), false);
}
public componentDidUpdate(prevProps: DocumentationProps, prevState: DocumentationState) {
public componentDidUpdate(prevProps: DocumentationProps, prevState: DocumentationState): void {
if (!_.isEqual(prevProps.docAgnosticFormat, this.props.docAgnosticFormat)) {
const hash = window.location.hash.slice(1);
sharedUtils.scrollToHash(hash, sharedConstants.SCROLL_CONTAINER_ID);
}
}
public render() {
public render(): React.ReactNode {
const styles: Styles = {
mainContainers: {
position: 'absolute',
@@ -157,7 +157,7 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
</div>
);
}
private _renderLoading(mainContainersStyles: React.CSSProperties) {
private _renderLoading(mainContainersStyles: React.CSSProperties): React.ReactNode {
return (
<div className="col col-12" style={mainContainersStyles}>
<div
@@ -289,7 +289,7 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
</div>
);
}
private _renderNetworkBadgesIfExists(sectionName: string) {
private _renderNetworkBadgesIfExists(sectionName: string): React.ReactNode {
if (this.props.docsInfo.type !== SupportedDocJson.Doxity) {
return null;
}
@@ -368,17 +368,17 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
/>
);
}
private _onSidebarHover(event: React.FormEvent<HTMLInputElement>) {
private _onSidebarHover(event: React.FormEvent<HTMLInputElement>): void {
this.setState({
isHoveringSidebar: true,
});
}
private _onSidebarHoverOff() {
private _onSidebarHoverOff(): void {
this.setState({
isHoveringSidebar: false,
});
}
private _onHashChanged(event: any) {
private _onHashChanged(event: any): void {
const hash = window.location.hash.slice(1);
sharedUtils.scrollToHash(hash, sharedConstants.SCROLL_CONTAINER_ID);
}

View File

@@ -7,7 +7,7 @@ export interface EnumProps {
values: EnumValue[];
}
export function Enum(props: EnumProps) {
export const Enum = (props: EnumProps) => {
const values = _.map(props.values, (value, i) => {
const defaultValueIfAny = !_.isUndefined(value.defaultValue) ? ` = ${value.defaultValue}` : '';
return `\n\t${value.name}${defaultValueIfAny},`;
@@ -20,4 +20,4 @@ export function Enum(props: EnumProps) {
{`}`}
</span>
);
}
};

View File

@@ -24,7 +24,7 @@ export class EventDefinition extends React.Component<EventDefinitionProps, Event
shouldShowAnchor: false,
};
}
public render() {
public render(): React.ReactNode {
const event = this.props.event;
const id = `${this.props.sectionName}-${event.name}`;
return (
@@ -49,7 +49,7 @@ export class EventDefinition extends React.Component<EventDefinitionProps, Event
</div>
);
}
private _renderEventCode() {
private _renderEventCode(): React.ReactNode {
const indexed = <span style={{ color: colors.green }}> indexed</span>;
const eventArgs = _.map(this.props.event.eventArgs, (eventArg: EventArg) => {
const type = (
@@ -76,7 +76,7 @@ export class EventDefinition extends React.Component<EventDefinitionProps, Event
</span>
);
}
private _setAnchorVisibility(shouldShowAnchor: boolean) {
private _setAnchorVisibility(shouldShowAnchor: boolean): void {
this.setState({
shouldShowAnchor,
});

View File

@@ -13,7 +13,7 @@ export interface InterfaceProps {
docsInfo: DocsInfo;
}
export function Interface(props: InterfaceProps) {
export const Interface = (props: InterfaceProps) => {
const type = props.type;
const properties = _.map(type.children, property => {
return (
@@ -63,4 +63,4 @@ export function Interface(props: InterfaceProps) {
{`}`}
</span>
);
}
};

View File

@@ -88,7 +88,7 @@ function renderParameters(
docsInfo: DocsInfo,
sectionName: string,
typeDefinitionByName?: TypeDefinitionByName,
) {
): React.ReactNode[] {
const params = _.map(parameters, (p: Parameter) => {
const isOptional = p.isOptional;
const hasDefaultValue = !_.isUndefined(p.defaultValue);
@@ -116,7 +116,7 @@ function renderTypeParameter(
docsInfo: DocsInfo,
sectionName: string,
typeDefinitionByName?: TypeDefinitionByName,
) {
): React.ReactNode {
const typeParam = (
<span>
{`<${typeParameter.name} extends `}

View File

@@ -42,7 +42,7 @@ export class SignatureBlock extends React.Component<SignatureBlockProps, Signatu
shouldShowAnchor: false,
};
}
public render() {
public render(): React.ReactNode {
const method = this.props.method;
if (typeDocUtils.isPrivateOrProtectedProperty(method.name)) {
return null;
@@ -111,14 +111,14 @@ export class SignatureBlock extends React.Component<SignatureBlockProps, Signatu
</div>
);
}
private _renderChip(text: string) {
private _renderChip(text: string): React.ReactNode {
return (
<div className="p1 mr1" style={styles.chip}>
{text}
</div>
);
}
private _renderParameterDescriptions(parameters: Parameter[]) {
private _renderParameterDescriptions(parameters: Parameter[]): React.ReactNode {
const descriptions = _.map(parameters, parameter => {
const isOptional = parameter.isOptional;
return (
@@ -146,7 +146,7 @@ export class SignatureBlock extends React.Component<SignatureBlockProps, Signatu
});
return descriptions;
}
private _setAnchorVisibility(shouldShowAnchor: boolean) {
private _setAnchorVisibility(shouldShowAnchor: boolean): void {
this.setState({
shouldShowAnchor,
});

View File

@@ -10,7 +10,7 @@ export interface SourceLinkProps {
version: string;
}
export function SourceLink(props: SourceLinkProps) {
export const SourceLink = (props: SourceLinkProps) => {
const src = props.source;
const sourceCodeUrl = `${props.sourceUrl}/${src.fileName}#L${src.line}`;
return (
@@ -20,4 +20,4 @@ export function SourceLink(props: SourceLinkProps) {
</a>
</div>
);
}
};

View File

@@ -3,7 +3,7 @@ import * as _ from 'lodash';
import * as React from 'react';
import { DocsInfo } from '../docs_info';
import { CustomType, CustomTypeChild, KindString, TypeDocTypes } from '../types';
import { CustomType, CustomTypeChild, EnumValue, KindString, TypeDocTypes } from '../types';
import { constants } from '../utils/constants';
import { utils } from '../utils/utils';
@@ -35,7 +35,7 @@ export class TypeDefinition extends React.Component<TypeDefinitionProps, TypeDef
shouldShowAnchor: false,
};
}
public render() {
public render(): React.ReactNode {
const customType = this.props.customType;
if (!this.props.docsInfo.isPublicType(customType.name)) {
return null; // no-op
@@ -129,7 +129,7 @@ export class TypeDefinition extends React.Component<TypeDefinitionProps, TypeDef
</div>
);
}
private _setAnchorVisibility(shouldShowAnchor: boolean) {
private _setAnchorVisibility(shouldShowAnchor: boolean): void {
this.setState({
shouldShowAnchor,
});
@@ -150,7 +150,7 @@ export class TypeDefinition extends React.Component<TypeDefinitionProps, TypeDef
*
* Each property description should be on a new line.
*/
private _formatComment(text: string) {
private _formatComment(text: string): string {
const NEW_LINE_REGEX = /(\r\n|\n|\r)/gm;
const sanitizedText = text.replace(NEW_LINE_REGEX, ' ');
const PROPERTY_DESCRIPTION_DIVIDER = ':';