This repository was archived by the owner on Dec 24, 2025. It is now read-only.
Repository navigation
Conversation
added 2 commits
June 8, 2019 21:55
Summary: This prevents unsafe operations since mutable covariant arrays can no longer be assigned to their contravariant. TODO: hide this new behavior behind a flag Test Plan: - yarn gulp build-min - node built/local/tsc.js --skipLibCheck --strict --noEmit foo.ts
Owner
Author
|
There's still an issue with object's and their properties always being covariant which makes aliasing assignments of objects unsafe: type NumberNode = { id: number };
const node0: NumberNode = { id: 5 };
type MixedNode = { id: number | string };
const node1: MixedNode = { id: 5 };
const node2: MixedNode = node0; // This should fail, but doesn't
node2.id = "five"; // whoops, now node0 has a string for its "id"
const node3: Readonly<MixedNode> = node0; // This okay b/c node3 is readonly |
Owner
Author
now fails as expected, but other types of object properties need to be updated to behave the same way, i.e. invariant when assigning a variable but covariant when assigning an object literal or covariant when being assigned to |
Owner
Author
|
Closing in preference of #4. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This prevents unsafe operations since mutable covariant arrays can no longer be assigned to their contravariant.
This refactored
isRelatedToand similar functions to accept an options object which made feeding the current node,errorNode, down torecursiveTypeRelatedTobefore computingvariancesto override the default variance for type parameters which is nowinvariantto becovariantfor array literals only.It also updates
getRelationKeyto also take anerrorNodewhich is used to differentiate the relation key when the source is an array literal. This allowsisTypeRelatedToto return different results depending on whether an array literal or a non-literal array with the same type are the source.TODO:
Test Plan:
foo.ts: