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

[#IP-84] Change strict configuration to true #20

Merged
merged 8 commits into from
Apr 13, 2021

Conversation

fabriziopapi
Copy link
Contributor

List of Changes

Set the stirct configuration to true.
Fixed the compilation errors caused by the new settings.

Motivation and Context

The configuration strict set to true will help to reduce errors enforcing a less forgiving TS compiler.

How Has This Been Tested?

The changes have been tested running again the provided unit tests.

Screenshots (if appropriate):

Types of changes

  • Chore (nothing changes by a user perspective)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@pagopa-github-bot
Copy link
Contributor

pagopa-github-bot commented Apr 1, 2021

Warnings
⚠️ Please include a Pivotal story at the beginning of the PR title (see below).

Example of PR titles that include pivotal stories:

  • single story: [#123456] my PR title
  • multiple stories: [#123456,#123457,#123458] my PR title

Generated by 🚫 dangerJS against b2819af

@codecov
Copy link

codecov bot commented Apr 1, 2021

Codecov Report

Merging #20 (b2819af) into master (55f4a16) will increase coverage by 0.26%.
The diff coverage is 82.35%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #20      +/-   ##
==========================================
+ Coverage   87.70%   87.97%   +0.26%     
==========================================
  Files          22       22              
  Lines         431      424       -7     
  Branches       43       42       -1     
==========================================
- Hits          378      373       -5     
+ Misses         52       50       -2     
  Partials        1        1              
Impacted Files Coverage Δ
...ateOrUpdateInstallationCallOrchestrator/handler.ts 100.00% <ø> (ø)
...dleNHDeleteInstallationCallOrchestrator/handler.ts 100.00% <ø> (ø)
HandleNHNotificationCallActivity/handler.ts 96.96% <ø> (+7.78%) ⬆️
HandleNHNotifyMessageCallOrchestrator/handler.ts 100.00% <ø> (ø)
utils/durable/activities/log.ts 50.00% <40.00%> (-25.00%) ⬇️
HandleNHDeleteInstallationCallActivity/handler.ts 100.00% <100.00%> (ø)
HandleNHDeleteInstallationCallActivity/index.ts 100.00% <100.00%> (ø)
HandleNHNotifyMessageCallActivity/handler.ts 100.00% <100.00%> (ø)
utils/durable/activities/index.ts 93.33% <100.00%> (+0.47%) ⬆️
utils/durable/orchestrators/index.ts 83.78% <100.00%> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a319dd8...b2819af. Read the comment docs.

@balanza balanza mentioned this pull request Apr 12, 2021
6 tasks
throw new Error(`Unexpected object: ${toString(x)}`);
};
// tslint:disable:no-any
const createUnexpecterError = (x: any): Error =>
Copy link
Contributor

Choose a reason for hiding this comment

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

The whole point of assertNever is to have an assignment to a variable of type never; that means no other type can be passed to such function except never. This is an important mechanism to mark death branches in code (that is: conditions we assert are impossible to happen), and it is at foundation of every exhaustive check.

That said, the return type is not important because the functions either is never called or TS fails with wrong arguments error.

What about runtime? If this functions is executed, it means the variable contains a value which shape differs from the declared type. As this is a problem that can make the whole execution inconsistent, it's safer to throw an exception and let the error to bubble up.

@@ -87,7 +88,7 @@ export const getCallNHServiceActivityHandler = (
return failure(e.message);
});
default:
assertNever(message);
throw createUnexpecterError(message);
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment above

utils/notification.ts Outdated Show resolved Hide resolved
@balanza balanza marked this pull request as ready for review April 13, 2021 09:54
@balanza balanza requested a review from gquadrati as a code owner April 13, 2021 09:54
@balanza
Copy link
Contributor

balanza commented Apr 13, 2021

We needed to undergo a huge refactor in 0d28679 in order to make the newly-introduced utils/durable module to cope with strict mode.
Breaking changes have been introduced to the type system:

  • ActivityBody is no longer used to fully define an activity signature; that is, we no longer refer ActivityBody as type variable when using createActivity or callableActivity. Instead, we pass Input, Success, Failure triplet.

This wasn't intended but needed in order for input and output types to be fully instantiated.

We're loosing the hard coupling between input and output of an activity - other said: an orchestrator can create an arbitrary pair input/output for an activity, and the type system is not covering us from such errors. These would be gross errors and easy to spot at code review, however I'm not happy with the result and I commit to improve such type definitions.
Anyway, it works now.

Luckily, we didn't have to touch the implementation.

@balanza balanza dismissed their stale review April 13, 2021 10:20

new changes came

Copy link
Contributor

@gquadrati gquadrati left a comment

Choose a reason for hiding this comment

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

LGTM apart from a few changes

notifyMessageActivity: CallableActivity<NotifyMessageActivityBodyImpl>;
notifyMessageActivity: CallableActivity<
NotifyMessageActivityInput,
NotifyMessageActivityResultSuccess
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the need of specifying also the success type, since it's a simple ActivityResultSuccess?

Copy link
Contributor

Choose a reason for hiding this comment

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

Just for more consistency. As we lost the ActivityBody here, there's no other mechanism that is ensuring us to use the very same output type of the activity.

Thinking about making S non-optional for callableActivity....

Copy link
Contributor

Choose a reason for hiding this comment

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

We could think about exporting the callableActivity directly from the activity itself, what do you think?
So it's up to the activity expose it with right types

Copy link
Contributor

Choose a reason for hiding this comment

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

Or more: we could just scaffold all types so that we don't have to use so much generics

utils/durable/orchestrators/index.ts Show resolved Hide resolved
yarn.lock Outdated Show resolved Hide resolved
Emanuele De Cupis and others added 2 commits April 13, 2021 12:51
Co-authored-by: gquadrati <75862507+gquadrati@users.noreply.github.com>
@gquadrati gquadrati merged commit 6cf783c into master Apr 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants