From e97722eb0ee7295e97697c2823b46a17ff404d9f Mon Sep 17 00:00:00 2001 From: Drew Hays Date: Wed, 5 Jul 2017 12:30:20 -0700 Subject: [PATCH] fix "expect" in tslint --- types/next/index.d.ts | 16 +++++++++------ types/next/next-tests.ts | 42 ++++++++++++++++++++-------------------- types/next/tslint.json | 11 +---------- 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/types/next/index.d.ts b/types/next/index.d.ts index 51024ffc8f..7f8eb6b18f 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/zeit/next.js // Definitions by: Drew Hays // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 /// @@ -106,11 +107,13 @@ declare module 'next/link' { } declare module 'next/dynamic' { + type ComponentType = React.StatelessComponent | typeof React.Component; + interface DynamicOptions { - loading?: React.ComponentType; + loading?: ComponentType; ssr?: boolean; - modules?(props: TCProps & TLProps): { [key: string]: Promise> }; - render?(props: TCProps & TLProps, modules: { [key: string]: React.ComponentType }): void; + modules?(props: TCProps & TLProps): { [key: string]: Promise> }; + render?(props: TCProps & TLProps, modules: { [key: string]: ComponentType }): void; } class SameLoopPromise extends Promise { @@ -119,11 +122,12 @@ declare module 'next/dynamic' { setError(value: any): void; runIfNeeded(): void; } - export default function(componentPromise: Promise>, options?: DynamicOptions): React.ComponentType; + export default function(componentPromise: Promise>, options?: DynamicOptions): ComponentType; } declare module 'next/router' { import * as url from 'url'; + type ComponentType = React.StatelessComponent | typeof React.Component; interface EventChangeOptions { shallow?: boolean; @@ -136,7 +140,7 @@ declare module 'next/router' { ready(cb: RouterCallback): void; // router properties - readonly components: { [key: string]: { Component: React.ComponentType, err: any } }; + readonly components: { [key: string]: { Component: ComponentType, err: any } }; readonly pathname: string; readonly route: string; readonly asPath: string; @@ -147,7 +151,7 @@ declare module 'next/router' { back(): void; push(url: string, as?: string, options?: EventChangeOptions): Promise; replace(url: string, as?: string, options?: EventChangeOptions): Promise; - prefetch(url: string): Promise>; + prefetch(url: string): Promise>; // router events onAppUpdated?(nextRoute: string): void; diff --git a/types/next/next-tests.ts b/types/next/next-tests.ts index 3c216d770d..bfa93bfff8 100644 --- a/types/next/next-tests.ts +++ b/types/next/next-tests.ts @@ -24,31 +24,31 @@ server.defineRoutes().then(voidFunc); server.start().then(voidFunc); const parsedUrl = url.parse('https://www.example.com'); -const req: http.IncomingMessage = null; -const res: http.ServerResponse = null; const handler = server.getRequestHandler(); -handler(req, res); -handler(req, res, parsedUrl).then(voidFunc); -server.run(req, res, parsedUrl).then(voidFunc); +function handle(req: http.IncomingMessage, res: http.ServerResponse) { + handler(req, res); + handler(req, res, parsedUrl).then(voidFunc); + server.run(req, res, parsedUrl).then(voidFunc); -server.render(req, res, '/path/to/resource', null, parsedUrl).then(voidFunc); -server.render(req, res, '/path/to/resource', { key: 'value' }, parsedUrl).then(voidFunc); -server.renderError(new Error(), req, res, '/path/to/resource', { key: 'value' }).then(voidFunc); -server.renderError('this can be an error, too!', req, res, '/path/to/resource', { key: 'value' }).then(voidFunc); -server.render404(req, res, parsedUrl).then(voidFunc); + server.render(req, res, '/path/to/resource', {}, parsedUrl).then(voidFunc); + server.render(req, res, '/path/to/resource', { key: 'value' }, parsedUrl).then(voidFunc); + server.renderError(new Error(), req, res, '/path/to/resource', { key: 'value' }).then(voidFunc); + server.renderError('this can be an error, too!', req, res, '/path/to/resource', { key: 'value' }).then(voidFunc); + server.render404(req, res, parsedUrl).then(voidFunc); -server.renderToHTML(req, res, '/path/to/resource', { foo: 'bar' }).then(x => x.split('\n')); -server.renderErrorToHTML(new Error(), req, res, '/path/to/resource', { foo: 'bar' }).then(x => x.split('\n')); + server.renderToHTML(req, res, '/path/to/resource', { foo: 'bar' }).then(x => x.split('\n')); + server.renderErrorToHTML(new Error(), req, res, '/path/to/resource', { foo: 'bar' }).then(x => x.split('\n')); -server.serveStatic(req, res, '/path/to/thing').then(voidFunc); + server.serveStatic(req, res, '/path/to/thing').then(voidFunc); -let b: boolean; -b = server.isServeableUrl('/path/to/thing'); -b = server.isInternalUrl(req); -b = server.handleBuildId('{buildId}', res); + let b: boolean; + b = server.isServeableUrl('/path/to/thing'); + b = server.isInternalUrl(req); + b = server.handleBuildId('{buildId}', res); -const s: string = server.readBuildId(); -server.getCompilationError('page', req, res).then(err => err.thisIsAnAny); -server.handleBuildHash('filename', 'hash', res); -server.send404(res); + const s: string = server.readBuildId(); + server.getCompilationError('page', req, res).then(err => err.thisIsAnAny); + server.handleBuildHash('filename', 'hash', res); + server.send404(res); +} diff --git a/types/next/tslint.json b/types/next/tslint.json index e4a2c8f088..98f9451050 100644 --- a/types/next/tslint.json +++ b/types/next/tslint.json @@ -4,15 +4,6 @@ // All of the different "export default" lines in the index.d.ts // appear to be triggering this. Remove this when I know of a way // to declare a default export across multiple package/subpackages. - "strict-export-declare-modifiers": false, - - // This is a pretty generic one to have to ignore, but it's because - // of the following error: - // `JSX element type '' does not have any construct or call signatures.` - // In all cases, the element's type is "React.ComponentType`, which is composed of either: - // - React.StatelessComponent, which has a call signature, or - // - React.ComponentClass, which as a construct signature. - // This seems like it might be a bug. - "expect": false + "strict-export-declare-modifiers": false } }