Address reviewer's comments

- Export functions instead of interfaces.

- Remove unnecessary generics.
This commit is contained in:
Huy Nguyen 2019-01-24 11:31:29 -05:00
parent 4457d1bd8c
commit dd20246d10
4 changed files with 20 additions and 18 deletions

View File

@ -7,8 +7,5 @@ export interface LanguageNegotiationOptions {
strategy?: 'filtering' | 'matching' | 'lookup';
defaultLocale?: string;
}
export interface NegotiateLanguages {
(requestedLocales: ReadonlyArray<string>, availableLocales: ReadonlyArray<string>, options?: LanguageNegotiationOptions): string[];
}
export const negotiateLanguages: NegotiateLanguages;
export function negotiateLanguages(requestedLocales: ReadonlyArray<string>, availableLocales: ReadonlyArray<string>, options?: LanguageNegotiationOptions): string[];

View File

@ -29,6 +29,7 @@ ReactDOM.render(
interface Props {
getString: GetString;
otherProp: number;
someOtherProp: string;
}
function HelloButton(props: Props) {
const { getString } = props;
@ -42,6 +43,18 @@ function HelloButton(props: Props) {
const LocalizedHelloButton = withLocalization(HelloButton);
// Remove `getString` from list of required props:
const Test2 = () => (
<LocalizedHelloButton otherProp={2} someOtherProp='abc'/>
);
// Should not allow `getString` prop:
const Test3 = () => (
// $ExpectError
<LocalizedHelloButton otherProp={2} someOtherProp='abc' getString={() => {}}/>
);
// Should not allow any other props to be omitted:
const Test4 = () => (
// $ExpectError
<LocalizedHelloButton otherProp={2}/>
);

View File

@ -94,13 +94,8 @@ export interface InjectedProps {
// https://github.com/Microsoft/TypeScript/wiki/What%27s-new-in-TypeScript#predefined-conditional-types
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
// Injects `getString` and removes it from the prop requirements.
// Will not pass through `getString` if it's passed in during
// render.
export interface WithLocalization {
<TNeedProps, C extends React.ComponentType<Matching<InjectedProps, GetProps<C>>>>(
component: C
): React.ComponentType<Omit< GetProps<C>, keyof Shared<InjectedProps, GetProps<C>>> & TNeedProps>;
}
export const withLocalization: WithLocalization;
// Injects `getString` and removes it from the prop requirements. Will not pass
// through `getString` if it's passed in during render.
export function withLocalization<C extends React.ComponentType<Matching<InjectedProps, GetProps<C>>>>(
component: C
): React.ComponentType<Omit< GetProps<C>, keyof Shared<InjectedProps, GetProps<C>>>>;

View File

@ -1,6 +1,3 @@
{
"extends": "dtslint/dt.json",
"rules": {
"no-unnecessary-generics": false
}
"extends": "dtslint/dt.json"
}