Skip to content

WebApp [Typescript]: Update TS version to 4.7.2

Administrator requested to merge vk/update-ts-version-4.7.2 into main

Created by: vovakulikov

Closes https://github.com/sourcegraph/sourcegraph/issues/36211

Background

This PR tries to update Typescript from our current version 4.5.2 to the 4.7.2 version. You can read TS changelog about the 4.7.2 here.

So far we got a lot of errors around error handling in fetch methods that use the old way to fetch and handle data - fetching via requestGraphQL method.

In the nutshell the problem is that we have a following types about requestGraphQL method's result type

const requestGraphQL = <TResult, TVariables = object>(
    request: string,
    variables?: TVariables
): Observable<GraphQLResult<TResult>>

interface SuccessGraphQLResult<T> {
    data: T
    errors: undefined
}

 interface ErrorGraphQLResult {
    data: undefined
    errors: readonly GraphQLError[]
}

type GraphQLResult<T> = SuccessGraphQLResult<T> | ErrorGraphQLResult

Based on this types we can say that if we have some data we don't have any error in errors field. But in our codebase when we do have the following check

if (!data || (errors && errors.length > 0)) {
  eventLogger.log('CreateAccessTokenFailed')
  throw createAggregateError(errors)
}

and as you can see after the !data checks it isn't possible to have any errors in the next check (errors && errors.length > 0) and we're getting TS error that Property 'length' does not exist on type 'never'. Which is correct from TS point of view, but it seems like in reality we could have some errors even if we have some data in the data field. Check out these data handling checks

So we could just leave this with ts-ingore statements since requestGraphQL is deprecated method of data fetching or we should revisit our types around this method to solve this.

If you have any thoughts on this problems please feel free to step up and make a commit in this PR.

Test plan

  • Make sure that CI doesn't have any TS compile errors

App preview:

Check out the client app preview documentation to learn more.

Merge request reports

Loading