-
Notifications
You must be signed in to change notification settings - Fork 795
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
chore(typescript): enable useUnknownInCatchVariables in core #3211
Conversation
throw realpathErr; | ||
} catch (realpathErr: unknown) { | ||
if (realpathErr instanceof Object && 'code' in realpathErr) { | ||
// @ts-ignore: we've determined 'code' is in the prototype chain, but TS isn't happy about the access |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: This is because in
isn't a type guard: microsoft/TypeScript#21732. One option would be to implement a type guard function for NodeJS.ErrnoException
:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -139,9 +139,12 @@ export const createCustomResolverSync = ( | |||
const fsFilePath = normalizeFsPath(p); | |||
try { | |||
return sys.realpathSync(fsFilePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to your changes... does this even throw an exception? According to the interface of sys.realpathSync()
it returns a CompilerSystemRealpathResults
and doesn't throw an exception:
stencil/src/declarations/stencil-public-compiler.ts
Lines 1032 to 1035 in b00585f
/** | |
* SYNC! Does not throw. | |
*/ | |
realpathSync(p: string): CompilerSystemRealpathResults; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't, although I think the problem here is that we can't guarantee implementations on that interface won't throw. Perhaps this is just a bit of defensive programming?
this commit enables the 'useUnknownInCatchVariables' flag in the core compiler's tsconfig.json file. the remainder of the changes related directly to errors emitted by the TypeScript compiler as a result of this change. the most common change in this commit is updating a `catch` block that consists of a single call to stencil's `catchError` function. because `catchError` may theoretically accept a value or object that does not conform to the `Error` interface, we annotate many of the error variables declared in the `catch` block as type `any`, in a good-faith effort not to lose any useful information that we would otherwise turn into a `Diagnostic`. Using a type guard or other type narrowing mechanism would be feasible if any value that is not of type `Error` were logged in some other way. However in an attempt to not pollute the codebase with two different logging paths, we accept the ambiguity of `catchError` and catching errors of type `any` for the time being.
b88604b
to
f223d61
Compare
this commit is a quick fix for the browser-compile tests that currently do not compile after setting `useUnknownInCatchVariables` in #3211. This went unnoticed as this application is not currently type checked by our CI process. In order to get the application to compile, we type the error as `any` for now, with the intent of properly narrowing it in STENCIL-371 (and adding proper CI checks there as well). this commit only unblocks next monday's release.
this commit is a quick fix for the browser-compile tests that currently do not compile after setting `useUnknownInCatchVariables` in #3211. This went unnoticed as this application is not currently type checked by our CI process. In order to get the application to compile, we type the error as `any` for now, with the intent of properly narrowing it in STENCIL-371 (and adding proper CI checks there as well). this commit only unblocks next monday's release.
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run build
) was run locally and any changes were pushednpm test
) were run locally and passednpm run test.karma.prod
) were run locally and passednpm run prettier
) was run locally and passedPull request type
Please check the type of change your PR introduces:
What is the current behavior?
Errors declared in
catch
blocks are implicitly typed asany
GitHub Issue Number: N/A
What is the new behavior?
this commit enables the 'useUnknownInCatchVariables' flag in the core
compiler's tsconfig.json file. the remainder of the changes related
directly to errors emitted by the TypeScript compiler as a result of
this change.
the most common change in this commit is updating a
catch
block thatconsists of a single call to stencil's
catchError
function. becausecatchError
may theoretically accept a value or object that does notconform to the
Error
interface, we annotate many of the errorvariables declared in the
catch
block as typeany
, in a good-faitheffort not to lose any useful information that we would otherwise turn
into a
Diagnostic
. Using a type guard or other type narrowingmechanism would be feasible if any value that is not of type
Error
were logged in some other way. However in an attempt to not pollute the
codebase with two different logging paths, we accept the ambiguity of
catchError
and catching errors of typeany
for the time being.Does this introduce a breaking change?
Testing
The TS Compiler was run over the codebase, to ensure no type-safety issues. Admittedly it's not the most comprehensive, but covers most of the cases throughout this patch.
Other information
Do not merge please. Relies on #3205