diff --git a/.eslintrc.js b/.eslintrc.js index b81140d..d7a534e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,6 +1,7 @@ module.exports = { extends: ['airbnb-base', 'plugin:jest/recommended', 'plugin:prettier/recommended'], rules: { + 'dot-notation': 'off', 'no-nested-ternary': 'off', 'no-param-reassign': [ 'error', @@ -26,6 +27,7 @@ module.exports = { rules: { '@typescript-eslint/ban-types': 'off', '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', 'import/extensions': [ 'error', 'ignorePackages', diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03834e7..de6b303 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: with: node-version: ${{ matrix.node-version }} - name: Install dependencies - run: npm ci + run: npm ci --force - name: Lint run: npm run lint - name: Test diff --git a/package.json b/package.json index 2af5819..9a452db 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "scripts": { "lint": "eslint . --ext .ts,.js", "test": "jest", - "build": "node tools/build.js" + "build": "node tools/build.js", + "tsc": "tsc --noEmit" } } diff --git a/src/UniversalRouter.test.ts b/src/UniversalRouter.test.ts index ee847b8..be44e53 100644 --- a/src/UniversalRouter.test.ts +++ b/src/UniversalRouter.test.ts @@ -514,7 +514,7 @@ test('respects baseUrl', async () => { expect(action.mock.calls[0][0]).toHaveProperty('pathname', '/base/a/b/c') expect(action.mock.calls[0][0]).toHaveProperty('path', '/c') expect(action.mock.calls[0][0]).toHaveProperty('baseUrl', '/base/a/b') - expect(action.mock.calls[0][0]).toHaveProperty('route', routes.children[0].children[0]) + expect(action.mock.calls[0][0]).toHaveProperty('route', routes.children[0]?.children[0]) expect(action.mock.calls[0][0]).toHaveProperty('router', router) let err diff --git a/src/UniversalRouter.ts b/src/UniversalRouter.ts index ab18449..0cebb39 100644 --- a/src/UniversalRouter.ts +++ b/src/UniversalRouter.ts @@ -190,7 +190,7 @@ function matchRoute( if (matchResult && route.children) { while (childIndex < route.children.length) { if (!childMatches) { - const childRoute = route.children[childIndex] + const childRoute = route.children[childIndex]! childRoute.parent = route childMatches = matchRoute( @@ -320,7 +320,7 @@ class UniversalRouter { }) } - context.next = next + context['next'] = next return Promise.resolve() .then(() => next(true, this.root)) diff --git a/src/UniversalRouterSync.test.ts b/src/UniversalRouterSync.test.ts index b118456..0be5843 100644 --- a/src/UniversalRouterSync.test.ts +++ b/src/UniversalRouterSync.test.ts @@ -511,7 +511,7 @@ test('respects baseUrl', () => { expect(action.mock.calls[0][0]).toHaveProperty('pathname', '/base/a/b/c') expect(action.mock.calls[0][0]).toHaveProperty('path', '/c') expect(action.mock.calls[0][0]).toHaveProperty('baseUrl', '/base/a/b') - expect(action.mock.calls[0][0]).toHaveProperty('route', routes.children[0].children[0]) + expect(action.mock.calls[0][0]).toHaveProperty('route', routes.children[0]?.children[0]) expect(action.mock.calls[0][0]).toHaveProperty('router', router) let err diff --git a/src/UniversalRouterSync.ts b/src/UniversalRouterSync.ts index 1ec26bd..854f724 100644 --- a/src/UniversalRouterSync.ts +++ b/src/UniversalRouterSync.ts @@ -191,7 +191,7 @@ function matchRoute( if (matchResult && route.children) { while (childIndex < route.children.length) { if (!childMatches) { - const childRoute = route.children[childIndex] + const childRoute = route.children[childIndex]! childRoute.parent = route childMatches = matchRoute( @@ -318,7 +318,7 @@ class UniversalRouterSync { return next(resume, parent, result) } - context.next = next + context['next'] = next try { return next(true, this.root) diff --git a/src/generateUrls.ts b/src/generateUrls.ts index 44ae158..ed7d68c 100644 --- a/src/generateUrls.ts +++ b/src/generateUrls.ts @@ -57,7 +57,7 @@ function cacheRoutes( if (routes) { for (let i = 0; i < routes.length; i++) { - const childRoute = routes[i] + const childRoute = routes[i]! const childName = childRoute.name childRoute.parent = route cacheRoutes( @@ -117,7 +117,7 @@ function generateUrls(router: UniversalRouter, options?: GenerateUrlsOptions): G const keys: Keys = Object.create(null) for (let i = 0; i < tokens.length; i++) { const token = tokens[i] - if (typeof token !== 'string') { + if (token && typeof token !== 'string') { keys[token.name] = true } } @@ -132,8 +132,8 @@ function generateUrls(router: UniversalRouter, options?: GenerateUrlsOptions): G const keys = Object.keys(params) for (let i = 0; i < keys.length; i++) { const key = keys[i] - if (!regexp.keys[key]) { - queryParams[key] = params[key] + if (key && !regexp.keys[key]) { + queryParams[key] = params[key] ?? '' } } const query = opts.stringifyQueryParams(queryParams) diff --git a/tsconfig.json b/tsconfig.json index ffdcf97..4c8f608 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,8 @@ "strict": true, "declaration": true, "noEmitOnError": true, + "noPropertyAccessFromIndexSignature": true, + "noUncheckedIndexedAccess": true, "noUnusedLocals": true, "noUnusedParameters": true, "sourceMap": true,