From d034fff65ae1b04bf1de4f6521cd688b8cf3aa1a Mon Sep 17 00:00:00 2001 From: Yuddomack <41747333+Yuddomack@users.noreply.github.com> Date: Fri, 22 Jul 2022 23:50:45 +0900 Subject: [PATCH] Remove unnecessary assertions (#38899) removed unnecessary assertions of variables to prevent misuse ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples) --- packages/next/shared/lib/router/router.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/next/shared/lib/router/router.ts b/packages/next/shared/lib/router/router.ts index daf100f8920..a92c196473d 100644 --- a/packages/next/shared/lib/router/router.ts +++ b/packages/next/shared/lib/router/router.ts @@ -172,7 +172,7 @@ function omit( const omitted: { [key: string]: any } = {} Object.keys(object).forEach((key) => { if (!keys.includes(key as K)) { - omitted[key as string] = object[key] + omitted[key] = object[key] } }) return omitted as Omit @@ -292,16 +292,16 @@ function prepareUrlAs(router: NextRouter, url: Url, as?: Url) { } function resolveDynamicRoute(pathname: string, pages: string[]) { - const cleanPathname = removeTrailingSlash(denormalizePagePath(pathname!)) + const cleanPathname = removeTrailingSlash(denormalizePagePath(pathname)) if (cleanPathname === '/404' || cleanPathname === '/_error') { return pathname } // handle resolving href for dynamic routes - if (!pages.includes(cleanPathname!)) { + if (!pages.includes(cleanPathname)) { // eslint-disable-next-line array-callback-return pages.some((page) => { - if (isDynamicRoute(page) && getRouteRegex(page).re.test(cleanPathname!)) { + if (isDynamicRoute(page) && getRouteRegex(page).re.test(cleanPathname)) { pathname = page return true } @@ -732,7 +732,7 @@ export default class Router implements BaseRouter { const autoExportDynamic = isDynamicRoute(pathname) && self.__NEXT_DATA__.autoExport - this.basePath = (process.env.__NEXT_ROUTER_BASEPATH as string) || '' + this.basePath = process.env.__NEXT_ROUTER_BASEPATH || '' this.sub = subscription this.clc = null this._wrapApp = wrapApp