Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types)!: fix @netlify/headers-parser types #6104

Merged
merged 11 commits into from
Feb 28, 2025

Conversation

serhalp
Copy link
Contributor

@serhalp serhalp commented Feb 25, 2025

Summary

Fix poor/incorrect types

These types were very weak, containing plentiful anys, both explicit and implicit, as well as some incorrect inferred types. This overhauls those types and fixes uncovered errors.

(This is needed to fix type errors in the CLI.)

fix(@netlify/headers-parser)!: mark parseAllHeaders option minimal as required

All callers already pass in a non-nil boolean, so this is only technically breaking.

fix(@netlify/config)!: mark NetlifyTOML.headers[].values as required

This was just a mistake, but it is technically a breaking change.

Simplify/fix tsconfig strict config

We should be opting into strict mode and only opting out of some flags incrementally while we fix errors. The current setup makes this difficult.

This PR:

  • flips the global strict flag on
  • removes values redundantly being set to the default
  • stops disabling flags that obscured no errors (or very few, which I then fixed)
  • moves a few flag disables to the specific packages that require them
  • explicitly configures strict flags for already rather strict packages (just edge-bundler, and now also headers-parser)

There's a lot more work to do here, but this is a start...

@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "lib" /* Specify an output folder for all emitted files. */
"outDir": "lib" /* Specify an output folder for all emitted files. */,
"strictBindCallApply": false /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved this down to this specific package so I could enable it in the base config

@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "lib" /* Specify an output folder for all emitted files. */
"outDir": "lib" /* Specify an output folder for all emitted files. */,
"strictBindCallApply": false /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved this down to this specific package so I could enable it in the base config

@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "lib" /* Specify an output folder for all emitted files. */
"outDir": "lib" /* Specify an output folder for all emitted files. */,
"strictBindCallApply": false /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved this down to this specific package so I could enable it in the base config

@@ -2,6 +2,8 @@ import { promises as fs } from 'fs'
import { basename, extname, dirname, join } from 'path'

import isPathInside from 'is-path-inside'
// @ts-expect-error(serhalp) -- Remove once https://github.com/schnittstabil/merge-options/pull/28 is merged, or replace
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed worthwhile, as it allowed enabling noImplicitAny in zisi

Comment on lines -6 to +14
"strict": true
"noImplicitAny": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"useUnknownInCatchVariables": false,
"exactOptionalPropertyTypes": false,
"noImplicitReturns": false,
"noUncheckedIndexedAccess": false,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": false
Copy link
Contributor Author

@serhalp serhalp Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent here was presumably to opt into strict mode, but the tsconfig files get merged on a field-by-field basis... so "strict": true here wasn't really doing anything, as the specific flags were all still disabled from the base config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reenabled what I could but had to leave a few disabled 😞

serhalp added a commit to netlify/cli that referenced this pull request Feb 27, 2025
These types were very weak, containing plentiful `any`s, both explicit and implicit, as
well as some incorrect inferred types.
We should be opting *into* strict mode and only opting *out* of some flags incrementally
while we fix errors.

This commit:
- flips the global `strict` on
- removes values being set to the default via the above
- stops disabling flags that obscured no errors (or very few, which I then fixed)
- moves a few flag disablings to the specific packages that require it
- explictly configures strict flags for already rather strict packages
@serhalp serhalp force-pushed the serhalp/cpla-2534-fix-all-generated-ts-expect-errors branch from f53fa6b to 1fa08ca Compare February 27, 2025 21:15
@serhalp serhalp marked this pull request as ready for review February 27, 2025 21:23
@serhalp serhalp requested a review from a team as a code owner February 27, 2025 21:23
ndhoule
ndhoule previously approved these changes Feb 27, 2025
serhalp added a commit to netlify/cli that referenced this pull request Feb 27, 2025
serhalp added a commit to netlify/cli that referenced this pull request Feb 28, 2025
Copy link
Contributor

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@serhalp serhalp changed the title fix(types): fix @netlify/headers-parser types fix(types)!: fix @netlify/headers-parser types Feb 28, 2025
@serhalp serhalp force-pushed the serhalp/cpla-2534-fix-all-generated-ts-expect-errors branch from 41e53b7 to e339cc6 Compare February 28, 2025 16:27
Copy link
Contributor

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

Comment on lines 11 to 22
...input
minimal,
}: {
headersFiles?: undefined | string[]
netlifyConfigPath?: undefined | string
configHeaders?: undefined | MinimalHeader[]
minimal?: undefined | boolean
headersFiles: undefined | string[]
netlifyConfigPath: undefined | string
configHeaders: undefined | MinimalHeader[]
minimal: boolean
}) {
return await parseAllHeaders({
...(headersFiles && { headersFiles: headersFiles.map(addFileFixtureDir) }),
...(netlifyConfigPath && { netlifyConfigPath: addConfigFixtureDir(netlifyConfigPath) }),
configHeaders,
// Default `minimal` to `true` but still allows passing `undefined` to
// test the default value of that option
minimal: 'minimal' in input ? input.minimal : true,
minimal,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is the reason why all the test files had to change. And this change is because of the change to parseAllHeaders.

(Yes, parseHeaders calls parseAllHeaders and not the other way around 🙃)

@serhalp serhalp requested a review from ndhoule February 28, 2025 16:37
Copy link
Contributor

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@serhalp serhalp merged commit bc5e35a into main Feb 28, 2025
34 checks passed
@serhalp serhalp deleted the serhalp/cpla-2534-fix-all-generated-ts-expect-errors branch February 28, 2025 19:01
serhalp added a commit to netlify/cli that referenced this pull request Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants