-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Properly propagate ObjectFlags.NonInferrableType, clean up non-inferrable code paths #49887
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f6a2bed
Add test
jakebailey f5db542
Ensure flags are propogated when instantiating anonymous types
jakebailey 3f02cba
Always return on equal aliasSymbol
jakebailey b875b3e
Just use flag to check for non-inferrable types
jakebailey 66dbd1d
Eliminate nonInferrableType
jakebailey 0db958c
Also remove nonInferrableAnyType, which looks like it should have fla…
jakebailey 6dad0a4
Make autoType non-inferrable instead of checking explicitly
jakebailey 2974d9a
Rewrite and move comment to the correct place
jakebailey dd6bdaf
Give autoType its flags the normal way
jakebailey 4a73c1c
Make excludesKind optional in getPropagatingFlagsOfTypes
jakebailey 0972ebd
Rename test
jakebailey 28bc9d6
Add test from fp-ts
jakebailey 9e831ec
Remove old hack that skipped parameters during inference; this was re…
jakebailey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
tests/baselines/reference/nonInferrableTypePropagation1.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//// [nonInferrableTypePropagation1.ts] | ||
type Op<I, O> = (thing: Thing<I>) => Thing<O>; | ||
type Thing<T> = { | ||
value: T; | ||
pipe<A, B>( | ||
opA: Op<T, A>, | ||
opB: Op<A, B>, | ||
): Thing<B>; | ||
}; | ||
type Box<V> = { data: V }; | ||
|
||
declare const thing: Thing<number>; | ||
|
||
declare function map<T, R>(project: (value: T) => R): Op<T, R>; | ||
declare function tap<T>(next: (value: T) => void): Op<T, T>; | ||
declare function box<V>(data: V): Box<V>; | ||
declare function createAndUnbox<V>(factory: () => Thing<V | Box<V>>): Thing<V>; | ||
declare function log(value: any): void; | ||
|
||
const result1 = createAndUnbox(() => thing.pipe( | ||
map((data) => box(data)), | ||
tap((v) => log(v)), | ||
)); | ||
|
||
const result2 = createAndUnbox(() => thing.pipe( | ||
tap((v) => log(v)), | ||
map((data) => box(data)), | ||
)); | ||
|
||
|
||
//// [nonInferrableTypePropagation1.js] | ||
"use strict"; | ||
var result1 = createAndUnbox(function () { return thing.pipe(map(function (data) { return box(data); }), tap(function (v) { return log(v); })); }); | ||
var result2 = createAndUnbox(function () { return thing.pipe(tap(function (v) { return log(v); }), map(function (data) { return box(data); })); }); |
Oops, something went wrong.
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.
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.
Huh, this is interesting because this is redundant for
TypeReference
anonymous types (since those internally collect propagating flags from their type arguments), but required for any other anonymous object type with an alias. Go figure. I wonder if we should be propagating these object flags through conditional types, too... We already preserve them through intersections and unions. (We probably should be, since conditionals are "smart unions"...)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.
Yes, I think they should. Right now I'm trying to go by hand to every
createAnonymousType
,createObjectType
,... etc and see if there's anything missed, and it's a bit daunting because there's like 100 of them to verify, and nothing I've changed so far as actually changed any test.I want to have something I can run while I'm debugging that'll observe each type during inference and walk down to see if there was a
NonInferrableType
flag that was missed, but I get stuck in stack overflows, so I don't quite know how I can do my sanity check.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 think for this PR, I'm inclined to not try and go everywhere and add some more flag propagation without a way for me to check these; I just don't trust that I'm getting it right, and I don't have any way to observe the result.
This PR at least improves the one case I can test, and has a good amount of cleanup, so I'm happy with it (but I'll rerun the testing since I changed the structure of this quite a bit).