Skip to content

Commit

Permalink
feat: increase typescript strictness (#482)
Browse files Browse the repository at this point in the history
* feat: increase typescript strictness

* feat: increase typescript strictness

* feat: increase typescript strictness

* chore: deps update

* ci: latest yarn action
  • Loading branch information
belgattitude authored Jul 22, 2023
1 parent 091cad0 commit 5337e61
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 259 deletions.
7 changes: 7 additions & 0 deletions .changeset/twenty-numbers-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@httpx/dsn-parser': patch
'@httpx/exception': patch
'@httpx/json-api': patch
---

Improve typecheck strictness
27 changes: 21 additions & 6 deletions .github/actions/yarn-nm-install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# uses: ./.github/actions/yarn-nm-install #
# with: #
# enable-corepack: false # (default = 'false') #
# cache-npm-cache: false # (default = 'true') #
# cwd: ${{ github.workspace }}/apps/my-app # (default = '.') #
# cache-prefix: add cache key prefix # (default = 'default') #
# cache-node-modules: false # (default = 'false') #
Expand All @@ -18,6 +19,7 @@
# - latest: https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a #
# #
# Versions: #
# - 1.1.0 - 22-07-2023 - Option to enable npm global cache folder. #
# - 1.0.4 - 15-07-2023 - Fix corepack was always enabled. #
# - 1.0.3 - 05-07-2023 - YARN_ENABLE_MIRROR to false (speed up cold start) #
# - 1.0.2 - 02-06-2023 - install-state default to false #
Expand All @@ -33,9 +35,13 @@ inputs:
required: false
default: '.'
cache-prefix:
description: "Add a specific cache-prefix"
description: 'Add a specific cache-prefix'
required: false
default: 'default'
cache-npm-cache:
description: 'Cache npm global cache folder often used by node-gyp, prebuild binaries (invalidated on lock/os/node-version)'
required: false
default: 'true'
cache-node-modules:
description: 'Cache node_modules, might speed up link step (invalidated lock/os/node-version/branch)'
required: false
Expand All @@ -47,7 +53,7 @@ inputs:
enable-corepack:
description: 'Enable corepack'
required: false
default: 'false'
default: 'true'

runs:
using: 'composite'
Expand All @@ -69,6 +75,7 @@ runs:
echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
echo "CURRENT_NODE_VERSION="node-$(node --version)"" >> $GITHUB_OUTPUT
echo "CURRENT_BRANCH=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's,/,-,g')" >> $GITHUB_OUTPUT
echo "NPM_GLOBAL_CACHE_FOLDER=$(npm config get cache)" >> $GITHUB_OUTPUT
- name: ♻️ Restore yarn cache
uses: actions/cache@v3
Expand All @@ -87,6 +94,14 @@ runs:
path: ${{ inputs.cwd }}/**/node_modules
key: yarn-nm-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.yarn-config.outputs.CURRENT_BRANCH }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}

- name: ♻️ Restore global npm cache folder
if: inputs.cache-npm-cache == 'true'
id: npm-global-cache
uses: actions/cache@v3
with:
path: ${{ steps.yarn-config.outputs.NPM_GLOBAL_CACHE_FOLDER }}
key: npm-global-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}

- name: ♻️ Restore yarn install state
if: inputs.cache-install-state == 'true' && inputs.cache-node-modules == 'true'
id: yarn-install-state-cache
Expand All @@ -101,9 +116,9 @@ runs:
run: yarn install --immutable --inline-builds
env:
# Overrides/align yarnrc.yml options (v3, v4) for a CI context
YARN_ENABLE_GLOBAL_CACHE: 'false' # Use local cache folder to keep downloaded archives
YARN_ENABLE_MIRROR: 'false' # Prevent populating global cache for caches misses (local cache only)
YARN_NM_MODE: 'hardlinks-local' # Reduce node_modules size
YARN_ENABLE_GLOBAL_CACHE: 'false' # Use local cache folder to keep downloaded archives
YARN_ENABLE_MIRROR: 'false' # Prevent populating global cache for caches misses (local cache only)
YARN_NM_MODE: 'hardlinks-local' # Reduce node_modules size
YARN_INSTALL_STATE_PATH: '.yarn/ci-cache/install-state.gz' # Might speed up resolution step when node_modules present
# Other environment variables
HUSKY: '0' # By default do not run HUSKY install
HUSKY: '0' # By default do not run HUSKY install
3 changes: 1 addition & 2 deletions .ncurc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

# Add here exclusions on packages if any
reject: [
# example execa
# 'execa',
"rollup-plugin-swc3"
]
3 changes: 2 additions & 1 deletion examples/nextjs-app/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const {
module.exports = {
root: true,
parserOptions: {
project: __dirname + '/tsconfig.json',
tsconfigRootDir: __dirname,
project: 'tsconfig.json',
},
ignorePatterns: [...getDefaultIgnorePatterns()],
extends: [
Expand Down
14 changes: 7 additions & 7 deletions examples/nextjs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@
"@httpx/exception": "workspace:^",
"axios": "1.4.0",
"ky": "0.33.3",
"next": "13.4.10",
"next": "13.4.12",
"pino": "8.14.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"superjson": "1.12.4",
"superjson": "1.13.1",
"zod": "3.21.4"
},
"devDependencies": {
"@belgattitude/eslint-config-bases": "1.36.0",
"@types/node": "20.4.2",
"@belgattitude/eslint-config-bases": "1.37.0",
"@types/node": "20.4.4",
"@types/react": "18.2.15",
"@types/react-dom": "18.2.7",
"cross-env": "7.0.3",
"eslint": "8.45.0",
"eslint-config-next": "13.4.10",
"postcss": "8.4.26",
"eslint-config-next": "13.4.12",
"postcss": "8.4.27",
"rimraf": "5.0.1",
"tailwindcss": "3.3.3",
"typescript": "5.1.6",
"webpack": "5.88.1"
"webpack": "5.88.2"
}
}
33 changes: 17 additions & 16 deletions examples/nextjs-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"baseUrl": "./src",
"target": "esnext",
"module": "esnext",
"moduleResolution": "bundler",
"verbatimModuleSyntax": true,
"strict": true,
"strictNullChecks": true,
"incremental": true,
"lib": ["dom", "dom.iterable", "esnext"],
"baseUrl": ".",
"jsx": "preserve",
"paths": {
"@/backend": ["./backend/index"],
"@/lib": ["./lib/index"],
"@httpx/exception": ["../../../packages/exception/src/index"],
"@httpx/exception/serializer": [
"../../../packages/exception/src/serializer/index"
]
},
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"paths": {
"@/backend": ["./src/backend/index"],
"@/lib": ["./src/lib/index"],
"@httpx/exception": ["../../packages/exception/src/index"],
"@httpx/exception/serializer": [
"../../packages/exception/src/serializer/index"
]
}
"resolveJsonModule": true
},
"include": [
"next-env.d.ts",
Expand Down
13 changes: 10 additions & 3 deletions examples/nextjs-app/tsconfig.no-paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"paths": {
"@/backend": ["./src/backend/index"],
"@/lib": ["./src/lib/index"]
}
"@/backend": ["./backend/index"],
"@/lib": ["./lib/index"]
},
"allowJs": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"isolatedModules": true
}
}
5 changes: 4 additions & 1 deletion packages/dsn-parser/src/query-param-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export const parseQueryParams = (
const defaultValue = setTrueForUndefinedValues ? true : null;
const parts = queryParams.split('&').filter((v) => v.trim().length > 0);
return parts.reduce((acc, keyValuePair) => {
const [key, value = null] = keyValuePair.split('=');
const [key, value = null] = keyValuePair.split('=') as [
string,
string | undefined,
];
let val;
if (typeof value === 'string') {
if (parseNumbers && isParsableNumber(value)) {
Expand Down
5 changes: 1 addition & 4 deletions packages/dsn-parser/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"rootDir": "./src",
"baseUrl": ".",
"composite": false,
"noEmit": false,
"moduleResolution": "bundler",
"declaration": true,
"declarationMap": false,
"declarationDir": "./dist",
Expand Down
15 changes: 5 additions & 10 deletions packages/dsn-parser/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": "./src",
"module": "ESNext",
"moduleResolution": "node",
"target": "ESNext",
"lib": ["ESNext"],
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"noEmit": false,
"incremental": true,
"resolveJsonModule": true,
"target": "esnext",
"module": "esnext",
"moduleResolution": "bundler",
"verbatimModuleSyntax": true,
"strict": true,
"paths": {},
"types": ["vitest/globals"]
}
Expand Down
2 changes: 1 addition & 1 deletion packages/exception/src/base/HttpException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class HttpException extends Error {
* you can get back the error cause
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
*/
public readonly cause?: Error | HttpException;
public override readonly cause?: Error | HttpException;

/**
* Construct a new HttpException class
Expand Down
5 changes: 1 addition & 4 deletions packages/json-api/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"rootDir": "./src",
"baseUrl": ".",
"composite": false,
"noEmit": false,
"moduleResolution": "bundler",
"declaration": true,
"declarationMap": false,
"declarationDir": "./dist",
Expand Down
18 changes: 7 additions & 11 deletions packages/json-api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": "./src",
"module": "ESNext",
"moduleResolution": "node",
"target": "ESNext",
"lib": ["ESNext"],
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"noEmit": false,
"incremental": true,
"resolveJsonModule": true,
"types": ["vitest/globals"],
"target": "esnext",
"module": "esnext",
"moduleResolution": "bundler",
"verbatimModuleSyntax": true,
"strict": true,
"paths": {
"@httpx/exception": ["../../../packages/exception/src/index"]
}
},
"types": ["vitest/globals"]
}
}
5 changes: 5 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
"compilerOptions": {
"strict": true,
"useUnknownInCatchVariables": true,
"noImplicitOverride": true,
"noUncheckedIndexedAccess": true,
"allowUnreachableCode": false,
"noFallthroughCasesInSwitch": true,
"strictNullChecks": true,
"allowJs": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
Expand Down
Loading

0 comments on commit 5337e61

Please sign in to comment.