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

Simplify type checking for objects #11831

Merged
merged 2 commits into from
Jan 9, 2023
Merged

Conversation

msujew
Copy link
Member

@msujew msujew commented Nov 3, 2022

What it does

A follow up on #11490 (cc @paul-marechal)

Introduces an Is namespace with helpful methods to identify types. Uses the newly introduced methods to simplify type checking for objects. I didn't use the Is.string, Is.number etc functions as that would make the PR even larger and I wasn't sure whether it would make sense to use the functions that way anyway.

For some reason, this change required an additional call to reflect-metadata in the plugin host. Otherwise it would crash as the ContributionFilterRegistryImpl would try to annotate itself without the Reflect.hasOwnMetadata function available.

How to test

Nothing should've changed

Review checklist

Reminder for reviewers

@msujew msujew added the quality issues related to code and application quality label Nov 3, 2022
Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

@msujew should we maybe update packages/core/src/common/types.ts to include similar methods present in vscode (copying them over)?

As trivial as the checks might be I think unit-testing them might be good too.

@paul-marechal paul-marechal force-pushed the msujew/more-typing-improvements branch from edddeff to 5a852e6 Compare January 6, 2023 13:28
@paul-marechal
Copy link
Member

I pushed a commit with an alternative writing: The reasoning is that the function names should better describe what it does (isObject vs object) and if users want to use the functions under a namespace then can import as:

import * as types from '@theia/core/lib/common/types';
// ...
types.isObject(...);

msujew and others added 2 commits January 9, 2023 08:52
Cleanup our `packages/core/src/common/types.ts` file.
@paul-marechal paul-marechal force-pushed the msujew/more-typing-improvements branch from 9edcebb to 0fe602c Compare January 9, 2023 13:54
Copy link
Member

@paul-marechal paul-marechal left a comment

Choose a reason for hiding this comment

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

I like these new functions as they greatly help when dealing with unknown-typed variables!

@paul-marechal
Copy link
Member

@msujew feel free to merge if you agree with the changes suggested in the added commit, otherwise drop it before.

@msujew
Copy link
Member Author

msujew commented Jan 9, 2023

@paul-marechal Thanks, I didn't have time recently to update this PR :)

Your changes look good to me 👍

@msujew msujew merged commit 83b726e into master Jan 9, 2023
@msujew msujew deleted the msujew/more-typing-improvements branch January 9, 2023 15:41
@github-actions github-actions bot added this to the 1.34.0 milestone Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
quality issues related to code and application quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants