-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Enable strict mode in tsconfig and fix type errors #11200
Conversation
🦋 Changeset detectedLatest commit: 94b07f9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -1,14 +0,0 @@ | |||
export function filterInPlace<T>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file isn't used anywhere, nor is it exported. Hooray for removing unused code 🎉
size-limit report 📦
|
b49b269
to
6498326
Compare
0ce37f5
to
07ec4da
Compare
07ec4da
to
c3a761d
Compare
// FragmentRegistry constructor directly. This reserves the constructor for | ||
// future configuration of the FragmentRegistry. | ||
constructor(...fragments: DocumentNode[]) { | ||
this.resetCaches(); | ||
if (fragments.length) { | ||
this.register.apply(this, fragments); | ||
this.register(...fragments); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This transpiles to the old code, but if we switch to a newer target we save a few bytes.
@@ -778,20 +782,20 @@ class Stump extends Layer { | |||
return this; | |||
} | |||
|
|||
public merge() { | |||
public merge(older: string | StoreObject, newer: string | StoreObject) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This minifies even shorter than the old code.
public register(...fragments: DocumentNode[]): this { | ||
const definitions = new Map<string, FragmentDefinitionNode>(); | ||
arrayLikeForEach.call(arguments, (doc: DocumentNode) => { | ||
fragments.forEach((doc: DocumentNode) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2384d2383
< var arrayLikeForEach = Array.prototype.forEach;
2398a2398,2401
> var fragments = [];
> for (var _i = 0; _i < arguments.length; _i++) {
> fragments[_i] = arguments[_i];
> }
2400c2403
< arrayLikeForEach.call(arguments, function (doc) {
---
> fragments.forEach(function (doc) {
This transpiles slightly longer, are we okay with that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with it.
private data!: EntityStore; | ||
private optimisticData!: EntityStore; | ||
|
||
protected config: InMemoryCacheConfig; | ||
private watches = new Set<Cache.WatchOptions>(); | ||
private addTypename: boolean; | ||
|
||
private storeReader: StoreReader; | ||
private storeWriter: StoreWriter; | ||
private storeReader!: StoreReader; | ||
private storeWriter!: StoreWriter; | ||
private addTypenameTransform = new DocumentTransform(addTypenameToDocument); | ||
|
||
private maybeBroadcastWatch: OptimisticWrapperFunction< | ||
private maybeBroadcastWatch!: OptimisticWrapperFunction< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these are set in functions that are directly called from the constructor.
@@ -113,7 +114,7 @@ export class QueryInfo { | |||
// NetworkStatus.loading, but also possibly fetchMore, poll, refetch, | |||
// or setVariables. | |||
networkStatus?: NetworkStatus; | |||
observableQuery?: ObservableQuery<any>; | |||
observableQuery?: ObservableQuery<any, any>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are generally very inconsistent with the extends OperationVariables
on TVariables
, and I have to say I'm not too happy with OperationVariables
, as it works with type
-declared types, but not with interfaces (as those don't have an implicit index signature).
We might want to look into that - but not in this PR.
@@ -526,7 +530,7 @@ export class QueryManager<TStore> { | |||
// either a SingleExecutionResult or the final ExecutionPatchResult, | |||
// call the update function. | |||
if (isFinalResult) { | |||
update(cache, result, { | |||
update(cache as TCache, result, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the TCache
generic argument here is essentially an any
-cast. I'm not super happy about that, but on the other hand, realistically all the generic arguments on markMutationResult
are any-casts
export class HttpLink extends ApolloLink { | ||
public requester: RequestHandler; | ||
constructor(public options: HttpOptions = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requester
appears in the whole code base only here and it doesn't seem to be set or read anywhere - it's also not there at runtime. I guess this can be removed?
@@ -86,6 +86,7 @@ export function withMutation< | |||
|
|||
return ( | |||
<Mutation ignoreResults {...opts} mutation={document}> | |||
{/* @ts-expect-error */} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not gonna fix types in the old HOCs...
onError( | ||
error, | ||
clientOptions as MutationOptions<TData, OperationVariables> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to look closer into these, but for now I'm just casting them around..
This is ready for review now. |
@@ -146,7 +146,7 @@ describe("mergeDeep", function () { | |||
}); | |||
|
|||
it("supports custom reconciler functions", function () { | |||
const merger = new DeepMerger((target, source, key) => { | |||
const merger = new DeepMerger(function (target, source, key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit puzzled that this test worked... maybe that test needs deeper recursion?
f2555fa
to
c83b042
Compare
@@ -0,0 +1,2 @@ | |||
/** @internal */ | |||
export type TODO = any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this type for any
-casts we want to remove in the future (e.g. in a separate PR, like in this case). As it is imported everywhere, we can easily use TS to track all of it's usages down and eliminate them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it!
The base for this PR is now the Api-Extractor branch, so this PR can be reviewed, but not be merged before that other branch is merged. |
@@ -398,7 +398,7 @@ namespace Cache_2 { | |||
// (undocumented) | |||
interface BatchOptions<TCache extends ApolloCache<any>, TUpdateResult = void> { | |||
// (undocumented) | |||
onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult<any>, lastDiff: Cache_2.DiffResult<any> | undefined) => any; | |||
onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult<any>, lastDiff?: Cache_2.DiffResult<any> | undefined) => any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file sums up all the relevant changes to our external api. (The main entrypoint, that is)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've given this yet another full review, and I approve. @jerelmiller, please also give this another pass - and then let's get this in as soon as possible!
Closes #11199
Enables strict mode in our
tsconfig.json
and ensures our types/code are updated to handle the failures that arise from this change.Checklist: