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

Improving the overall type safety of the entire library #2917

Closed
wants to merge 3 commits into from
Closed

Improving the overall type safety of the entire library #2917

wants to merge 3 commits into from

Conversation

Idono87
Copy link
Contributor

@Idono87 Idono87 commented May 5, 2021

Description

This PR is an effort to improve the overall type safety of the entire library.

The lack of strictness is causing unintended behavior for projects relying on stricter type safety. To fix these issues typescript strictness rules have to be tightened. Types and code will have to be re written to conform to the stricter type checks.

Related #2907

Type of change

  • 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)
  • This change requires a documentation update

Further comments

This PR will take some time to complete but eventually give much stronger type safety.

@changeset-bot
Copy link

changeset-bot bot commented May 5, 2021

⚠️ No Changeset found

Latest commit: 65cb40a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"skipLibCheck": true,
Copy link
Owner

Choose a reason for hiding this comment

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

I am not sure if running type check for dependencies is a good idea. This might be overhead for our build process.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was an oversight by me. Thank you for spotting it.

@@ -15,4 +15,5 @@ module.exports = {
moduleNameMapper: pathsToModuleNameMapper(tsconfig.compilerOptions.paths, { prefix: `${ROOT_DIR}/` }),
collectCoverage: false,
cacheDirectory: resolve(ROOT_DIR, `${CI ? '' : 'node_modules/'}.cache/jest`),
preset: 'ts-jest',
Copy link
Owner

@ardatan ardatan May 5, 2021

Choose a reason for hiding this comment

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

I avoided to use ts-jest on purpose in order to have faster compilation and reduce overhead of tsc. I don't think we need type checking in tests. At least, it is not CI's job I believe. So it's done by babel already. I thought of removing ts-jest completely but I realized that we still need it for pathsToModuleNameMapper above to use paths from tsconfig file.

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 would agree that for most cases the CI should not have to run type checking. But for open source tools and libraries with advanced generic types like the ResolversComposerMapping type, they should absolutely be tested . They are still a written piece of code and should be treated as such since they are prone to errors like any other code.

Tsc and babel only validate that types are correct. They don't know how to test intended behavior within generic types and ultimately allows code like this to pass type checking

interface Resolvers {
  Query?: {
    foo: () => string
  }
}

export const rcMap: ResolversComposerMapping<Resolvers> = {
  Query: {
    foo: 'hello'
  }
}

I understand that faster compile times and less overhead is desired. But if it compromises type robustness then it's not a great trade-off and makes using said types superfluous since they might or might not work as intended.

@ardatan
Copy link
Owner

ardatan commented May 27, 2021

We are discussing to switch another testing framework and we decided on not to use ts-jest in the meanwhile at least until @n1ru4l 's PR get merged. So closing this issue for now.
#3010

@ardatan ardatan closed this May 27, 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.

2 participants