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

feat: assertion functions #107

Merged
merged 9 commits into from
Nov 30, 2021
Merged

feat: assertion functions #107

merged 9 commits into from
Nov 30, 2021

Conversation

woutermont
Copy link
Contributor

Signed-off-by: Wouter Termont [email protected]

@woutermont woutermont requested a review from lem-onade November 30, 2021 15:30
Copy link
Contributor

@lem-onade lem-onade left a comment

Choose a reason for hiding this comment

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

Looks good.

Consider the following:

let variable: string;
variable = functionThatMightReturnUndefined();
assert(!isUndefined(variable)); // yes?
someOtherFunction(variable); // this function's param is required

Will TS complain about someOtherFunction having an object that is possibly undefined or does it recognize it can't be after the assert (the same way a simple if (!variable) does)? Asking because I've had to put in a lot of these ifs lately by enabling strict mode in NDE's core package. (most of the inrupt sdk's data function return Thing | null)

packages/dgt-utils-core/tsconfig.json Outdated Show resolved Hide resolved
Comment on lines +1 to +5
registry=https://registry.npmjs.org/

@digita-ai:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${NPM_TOKEN}
always-auth=true
Copy link
Contributor

Choose a reason for hiding this comment

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

Not related to this PR in specific but these .npmrc files can be removed if we all npm login once with the access token which is currently in $NPM_TOKEN

(https://github.com/netwerk-digitaal-erfgoed/solid-crs/blob/master/docs/modules/manual/pages/install.adoc#configure-git)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does that go for all .nmprc files?

Copy link
Contributor

Choose a reason for hiding this comment

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

All .npmrc files, but looks like they should still exist, just not contain the authToken stuff.
See https://github.com/netwerk-digitaal-erfgoed/solid-crs/blob/master/.npmrc

Copy link
Contributor

Choose a reason for hiding this comment

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

But should probably be its own issue in another repo (or all repos)

@woutermont
Copy link
Contributor Author

About your example, @lem-onade: while you'll probably have to use assert(not(isUndefined(variable))), or some sugar like assert(isDefined(variable)) which I can easily add, the answer to your question is 'yes', TS will indeed now that it is defined after the assert.

@woutermont woutermont enabled auto-merge (squash) November 30, 2021 18:53
@woutermont woutermont merged commit d54cb75 into develop Nov 30, 2021
@woutermont woutermont deleted the feat/assertion-functions branch November 30, 2021 19:17
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.

2 participants