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

Added TypeScript type checker + Fixed type errors. #5780

Merged
merged 46 commits into from
Mar 17, 2020

Conversation

sainthkh
Copy link
Contributor

@sainthkh sainthkh commented Nov 23, 2019

What has been changed?

1. Added type checker done by tsc.

Screenshot from 2019-11-25 11-16-58

Peek 2020-01-16 10-38

npm run type-check command iterates folders in packages and check if it has tsconfig.json file and runs tsc command to check if there is a type error in files. It ignores cli folder because dtslint checks the types.

It doesn't completely remove dtslint for now because it cannot check the parameter or return type of a variable.

This command is added to CI.

Command Options

  • -p, --project: To list projects separated by commas (like reporter,runner).
  • --skip-lib-check: --skipLibCheck of tsc.
  • --ignore-progress: Ignores progress for CI. Without this, CI result looks like this.

2. Other code changes.

  • Removed copying @types from cli. It causes duplicate types and creates a lot of errors. Fixed a new feature introduced in TypeScript 2.9, import('npm-module').
  • Moved @types dependencies of cli from devDependencies to dependencies. Because they are used in types/index.d.ts.
  • Updated packages to fix type errors.
    • @types/chai: 4.1.7 -> 4.2.5 => We're using [email protected], but types weren't updated.
    • typescript: 3.5.3 -> 3.7.2 => To use window.NODE definition.
    • Removed typeRoots in reporter, runner tsconfig.json files.

Additional details

  • Why was this change necessary?

Currently, CI doesn't check type errors.

  • What is affected by this change?

When there is a type error, CI will fail.

  • Any implementation details to explain?

It uses tsc --noEmit to check errors.

How has the user experience changed?

N/A

PR Tasks

  • [NA] Have tests been added/updated?
  • Has the original issue been tagged with a release in ZenHub?
  • [NA] Has a PR for user-facing changes been opened in cypress-documentation?
  • [NA] Have API changes been updated in the type definitions?
  • [NA] Have new configuration options been added to the cypress.schema.json?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 23, 2019

Thanks for the contribution! Below are some guidelines Cypress uses when doing PR reviews.

  • Please write [WIP] in the title of your Pull Request if your PR is not ready for review - someone will review your PR as soon as the [WIP] is removed.
  • Please familiarize yourself with the PR Review Checklist and feel free to make updates on your PR based on these guidelines.

PR Review Checklist

If any of the following requirements can't be met, leave a comment in the review selecting 'Request changes', otherwise 'Approve'.

User Experience

  • The feature/bugfix is self-documenting from within the product.
  • The change provides the end user with a way to fix their problem (no dead ends).

Functionality

  • The code works and performs its intended function with the correct logic.
  • Performance has been factored in (for example, the code cleans up after itself to not cause memory leaks).
  • The code guards against edge cases and invalid input and has tests to cover it.

Maintainability

  • The code is readable (too many nested 'if's are a bad sign).
  • Names used for variables, methods, etc, clearly describe their function.
  • The code is easy to understood and there are relevant comments explaining.
  • New algorithms are documented in the code with link(s) to external docs (flowcharts, w3c, chrome, firefox).
  • There are comments containing link(s) to the addressed issue (in tests and code).

Quality

  • The change does not reimplement code.
  • There's not a module from the ecosystem that should be used instead.
  • There is no redundant or duplicate code.
  • There are no irrelevant comments left in the code.
  • Tests are testing the code’s intended functionality in the best way possible.

Internal

  • The original issue has been tagged with a release in ZenHub.

@sainthkh sainthkh changed the title wip Type check TypeScript codes. Added TypeScript type checker. Nov 25, 2019
@sainthkh sainthkh marked this pull request as ready for review November 25, 2019 06:53
@sainthkh
Copy link
Contributor Author

Note: electron-5 fail is a flaky test.

@sainthkh sainthkh changed the title Added TypeScript type checker. Added TypeScript type checker + Fixed type errors. Nov 26, 2019
@jennifer-shehane
Copy link
Member

@sainthkh Some failures in the type checks

> node scripts/type_check "--ignore-progress"


desktop-gui failed
node_modules/@cypress/schema-tools/src/api.ts:449:9 - error TS2769: No overload matches this call.
  Overload 1 of 6, '(fn: (x: BindOptions) => CustomFormats | undefined, list: readonly BindOptions[]): (CustomFormats | undefined)[]', gave the following error.
    Argument of type '<T>(obj: Record<"formats", T>) => T' is not assignable to parameter of type '(x: BindOptions) => CustomFormats | undefined'.
      Types of parameters 'obj' and 'x' are incompatible.
        Type 'BindOptions' is not assignable to type 'Record<"formats", CustomFormats | undefined>'.
          Property 'formats' is optional in type 'BindOptions' but required in type 'Record<"formats", CustomFormats | undefined>'.
  Overload 2 of 6, '(fn: (x: number | BindOptions | (() => string) | { (...items: ConcatArray<BindOptions>[]): BindOptions[]; (...items: (BindOptions | ConcatArray<BindOptions>)[]): BindOptions[]; } | ... 17 more ... | (() => IterableIterator<...>)) => any, list: BindOptions[]): readonly any[]', gave the following error.
    Argument of type '<T>(obj: Record<"formats", T>) => T' is not assignable to parameter of type '(x: number | BindOptions | (() => string) | { (...items: ConcatArray<BindOptions>[]): BindOptions[]; (...items: (BindOptions | ConcatArray<BindOptions>)[]): BindOptions[]; } | ((searchElement: BindOptions, fromIndex?: number | undefined) => number) | ((searchElement: BindOptions, fromIndex?: number | undefined) => number) | ((start?: number | undefined, end?: number | undefined) => BindOptions[]) | ((searchElement: BindOptions, fromIndex?: number | undefined) => boolean) | (() => string) | (<U>(callbackfn: (value: BindOptions, index: number, array: BindOptions[]) => U, thisArg?: any) => U[]) | { <S extends BindOptions>(callbackfn: (value: BindOptions, index: number, array: BindOptions[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: BindOptions, index: number, array: BindOptions[]) => unknown, thisArg?: any): BindOptions[]; } | ((callbackfn: (value: BindOptions, index: number, array: BindOptions[]) => unknown, thisArg?: any) => boolean) | ((separator?: string | undefined) => string) | ((callbackfn: (value: BindOptions, index: number, array: BindOptions[]) => unknown, thisArg?: any) => boolean) | ((callbackfn: (value: BindOptions, index: number, array: BindOptions[]) => void, thisArg?: any) => void) | { (callbackfn: (previousValue: BindOptions, currentValue: BindOptions, currentIndex: number, array: BindOptions[]) => BindOptions): BindOptions; (callbackfn: (previousValue: BindOptions, currentValue: BindOptions, currentIndex: number, array: BindOptions[]) => BindOptions, initialValue: BindOptions): BindOptions; <U>(callbackfn: (previousValue: U, currentValue: BindOptions, currentIndex: number, array: BindOptions[]) => U, initialValue: U): U; } | { (callbackfn: (previousValue: BindOptions, currentValue: BindOptions, currentIndex: number, array: BindOptions[]) => BindOptions): BindOptions; (callbackfn: (previousValue: BindOptions, currentValue: BindOptions, currentIndex: number, array: BindOptions[]) => BindOptions, initialValue: BindOptions): BindOptions; <U>(callbackfn: (previousValue: U, currentValue: BindOptions, currentIndex: number, array: BindOptions[]) => U, initialValue: U): U; } | { <S extends BindOptions>(predicate: (this: void, value: BindOptions, index: number, obj: BindOptions[]) => value is S, thisArg?: any): S | undefined; (predicate: (value: BindOptions, index: number, obj: BindOptions[]) => unknown, thisArg?: any): BindOptions | undefined; } | ((predicate: (value: BindOptions, index: number, obj: BindOptions[]) => unknown, thisArg?: any) => number) | (() => IterableIterator<[number, BindOptions]>) | (() => IterableIterator<number>) | (() => IterableIterator<BindOptions>)) => any'.
      Types of parameters 'obj' and 'x' are incompatible.
        Type 'number | BindOptions | (() => string) | { (...items: ConcatArray<BindOptions>[]): BindOptions[]; (...items: (BindOptions | ConcatArray<BindOptions>)[]): BindOptions[]; } | ((searchElement: BindOptions, fromIndex?: number | undefined) => number) | ((searchElement: BindOptions, fromIndex?: number | undefined) => number) | ((start?: number | undefined, end?: number | undefined) => BindOptions[]) | ((searchElement: BindOptions, fromIndex?: number | undefined) => boolean) | (() => string) | (<U>(callbackfn: (value: BindOptions, index: number, array: BindOptions[]) => U, thisArg?: any) => U[]) | { <S extends BindOptions>(callbackfn: (value: BindOptions, index: number, array: BindOptions[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: BindOptions, index: number, array: BindOptions[]) => unknown, thisArg?: any): BindOptions[]; } | ((callbackfn: (value: BindOptions, index: number, array: BindOptions[]) => unknown, thisArg?: any) => boolean) | ((separator?: string | undefined) => string) | ((callbackfn: (value: BindOptions, index: number, array: BindOptions[]) => unknown, thisArg?: any) => boolean) | ((callbackfn: (value: BindOptions, index: number, array: BindOptions[]) => void, thisArg?: any) => void) | { (callbackfn: (previousValue: BindOptions, currentValue: BindOptions, currentIndex: number, array: BindOptions[]) => BindOptions): BindOptions; (callbackfn: (previousValue: BindOptions, currentValue: BindOptions, currentIndex: number, array: BindOptions[]) => BindOptions, initialValue: BindOptions): BindOptions; <U>(callbackfn: (previousValue: U, currentValue: BindOptions, currentIndex: number, array: BindOptions[]) => U, initialValue: U): U; } | { (callbackfn: (previousValue: BindOptions, currentValue: BindOptions, currentIndex: number, array: BindOptions[]) => BindOptions): BindOptions; (callbackfn: (previousValue: BindOptions, currentValue: BindOptions, currentIndex: number, array: BindOptions[]) => BindOptions, initialValue: BindOptions): BindOptions; <U>(callbackfn: (previousValue: U, currentValue: BindOptions, currentIndex: number, array: BindOptions[]) => U, initialValue: U): U; } | { <S extends BindOptions>(predicate: (this: void, value: BindOptions, index: number, obj: BindOptions[]) => value is S, thisArg?: any): S | undefined; (predicate: (value: BindOptions, index: number, obj: BindOptions[]) => unknown, thisArg?: any): BindOptions | undefined; } | ((predicate: (value: BindOptions, index: number, obj: BindOptions[]) => unknown, thisArg?: any) => number) | (() => IterableIterator<[number, BindOptions]>) | (() => IterableIterator<number>) | (() => IterableIterator<BindOptions>)' is not assignable to type 'Record<"formats", CustomFormats | undefined>'.
          Type 'number' is not assignable to type 'Record<"formats", CustomFormats | undefined>'.
  Overload 3 of 6, '(fn: (x: BindOptions) => CustomFormats | undefined, obj: Functor<BindOptions>): Functor<CustomFormats | undefined>', gave the following error.
    Argument of type '<T>(obj: Record<"formats", T>) => T' is not assignable to parameter of type '(x: BindOptions) => CustomFormats | undefined'.
      Types of parameters 'obj' and 'x' are incompatible.
        Type 'BindOptions' is not assignable to type 'Record<"formats", CustomFormats | undefined>'.

449     map(prop('formats'), options),
            ~~~~~~~~~~~~~~~


node_modules/@cypress/schema-tools/src/trim.ts:25:13 - error TS2322: Type 'PlainObject' is not assignable to type 'never'.

25             trimmedObj[prop] = trimBySchema(schema[prop], object[prop])
               ~~~~~~~~~~~~~~~~

node_modules/@cypress/schema-tools/src/trim.ts:27:13 - error TS2322: Type 'PlainObject[]' is not assignable to type 'never'.

27             trimmedObj[prop] = map(trimBySchema(schema[prop]), object[prop])
               ~~~~~~~~~~~~~~~~


Found 3 errors.

@sainthkh
Copy link
Contributor Author

sainthkh commented Nov 27, 2019

@jennifer-shehane They're from schema-tools. I wrote PR for that. Please check PR comment above.

@sainthkh
Copy link
Contributor Author

  1. Fixed conflicts.
  2. Tests failed by flaky build.

@jennifer-shehane
Copy link
Member

@sainthkh There's some failures from our dtslint

Error: Errors in [email protected] for external dependencies:
../node_modules/@types/chai/index.d.ts(122,9): error TS8020: JSDoc types can only be used inside documentation comments.
../node_modules/@types/chai/index.d.ts(123,9): error TS8020: JSDoc types can only be used inside documentation comments.
../node_modules/@types/chai/index.d.ts(127,16): error TS2370: A rest parameter must be of an array type.

    at /root/cypress/cli/node_modules/dtslint/bin/index.js:190:19
    at Generator.next (<anonymous>)
    at fulfilled (/root/cypress/cli/node_modules/dtslint/bin/index.js:5:58)

@sainthkh
Copy link
Contributor Author

sainthkh commented Mar 9, 2020

  • Merged.
  • lint error is caused by @cypress-io/json-schemas
  • Other failures are flaky.

@jennifer-shehane
Copy link
Member

@sainthkh Sent an invite to give you permission to @cypress/json-schemas

@sainthkh
Copy link
Contributor Author

sainthkh commented Mar 12, 2020

Opened a PR in cypress-io/json-schemas#526.

Things to do:

  • The PR merged
  • json-schemas new version published
  • update it in desktop-gui

@tgriesser
Copy link
Member

@sainthkh changes should be published under 5.34.1

@sainthkh
Copy link
Contributor Author

  • Now lint-types passes.
  • 2 flaky tests.

CypressJoseph
CypressJoseph previously approved these changes Mar 13, 2020
Copy link
Contributor

@CypressJoseph CypressJoseph left a comment

Choose a reason for hiding this comment

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

LGTM! 👍 I love the new type_check script

@@ -1,4 +1,5 @@
import sinon from 'sinon'

Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: stray whitespace maybe?

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 might have added it to separate external dependencies and internal ones. But I think it doesn't matter to remove it.

@CypressJoseph CypressJoseph dismissed their stale review March 13, 2020 19:51

still failing specs?

@CypressJoseph CypressJoseph self-requested a review March 13, 2020 19:57
CypressJoseph
CypressJoseph previously approved these changes Mar 13, 2020
Copy link
Contributor

@CypressJoseph CypressJoseph left a comment

Choose a reason for hiding this comment

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

I needed to update dependencies, things are passing for me now! Please do fix any conflicts etc but this looks awesome 👍I will try to investigate getting the new command added to the CI flow for test-runner

@CypressJoseph CypressJoseph dismissed bahmutov’s stale review March 13, 2020 20:25

specs passing now :D

Comment on lines +323 to +324
- run:
command: yarn type-check --ignore-progress
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@CypressJoseph I added this to CI. Or is there anything more to do?

@CypressJoseph
Copy link
Contributor

CypressJoseph commented Mar 16, 2020 via email

Copy link
Contributor

@CypressJoseph CypressJoseph left a comment

Choose a reason for hiding this comment

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

Lgtm!! 🥂

@jennifer-shehane
Copy link
Member

@sainthkh We're planning to merge this into develop directly after the 4.2.0 release (which is today), so we can try it out in develop without potentially blocking our release.

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.

CI needs TypeScript type checker.
6 participants