-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix(expand): operator function signature #7256
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b7e7be4
fix(expand): correct function signature
dilame 562ad55
fix(expand): remove unused `ObservedValueOf` declaration
dilame 8929a29
fix(expand): one more attempt
dilame 5aa5e57
fix(expand): enforce the project function return type to be the same …
dilame 886152d
fix(expand/spec): correct signature of project function
dilame f4eac7f
fix(expand/spec-dtslint): remove testing of type inferring with diffe…
dilame 2f6cbca
fix(expand): simplify return type from OperatorFunction<T, T> to Mono…
dilame a02b360
fix(expand): complete OperatorFunction -> MonoTypeOperatorFunction re…
dilame e065b42
fix(expand): correct signature with the output type extension
dilame 8fd3e54
test(expand): should infer correctly with output type extending input…
dilame 2ecb234
fix(expand): justify the project output generic type
dilame ac471b4
test(expand): more dtslint cases for input/output compatibility
dilame 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 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 |
---|---|---|
@@ -1,51 +1,65 @@ | ||
import { of, asyncScheduler } from 'rxjs'; | ||
import { expand } from 'rxjs/operators'; | ||
|
||
it('should infer correctly', () => { | ||
const o = of(1, 2, 3).pipe(expand(value => of(value))); // $ExpectType Observable<number> | ||
const p = of(1, 2, 3).pipe(expand(value => [value])); // $ExpectType Observable<number> | ||
const q = of(1, 2, 3).pipe(expand(value => Promise.resolve(value))); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should infer correctly with a different type as the source', () => { | ||
const o = of(1, 2, 3).pipe(expand(value => of('foo'))); // $ExpectType Observable<string> | ||
const p = of(1, 2, 3).pipe(expand(value => ['foo'])); // $ExpectType Observable<string> | ||
const q = of(1, 2, 3).pipe(expand(value => Promise.resolve('foo'))); // $ExpectType Observable<string> | ||
}); | ||
|
||
it('should support a project function with index', () => { | ||
const o = of(1, 2, 3).pipe(expand((value, index) => of(index))); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should support concurrent parameter', () => { | ||
const o = of(1, 2, 3).pipe(expand(value => of(1), 47)); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should support a scheduler', () => { | ||
const o = of(1, 2, 3).pipe(expand(value => of(1), 47, asyncScheduler)); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should enforce types', () => { | ||
const o = of(1, 2, 3).pipe(expand()); // $ExpectError | ||
}); | ||
|
||
it('should enforce project types', () => { | ||
const o = of(1, 2, 3).pipe(expand((value: string, index) => of(1))); // $ExpectError | ||
const p = of(1, 2, 3).pipe(expand((value, index: string) => of(1))); // $ExpectError | ||
}); | ||
|
||
it('should enforce project return type', () => { | ||
const o = of(1, 2, 3).pipe(expand(value => 1)); // $ExpectError | ||
}); | ||
|
||
it('should enforce concurrent type', () => { | ||
const o = of(1, 2, 3).pipe(expand(value => of(1), 'foo')); // $ExpectError | ||
}); | ||
|
||
it('should enforce scheduler type', () => { | ||
const o = of(1, 2, 3).pipe(expand(value => of(1), 47, 'foo')); // $ExpectError | ||
}); | ||
|
||
it('should support union types', () => { | ||
const o = of(1).pipe(expand(x => typeof x === 'string' ? of(123) : of('test'))); // $ExpectType Observable<string | number> | ||
}); | ||
import { of, asyncScheduler } from 'rxjs'; | ||
import { expand } from 'rxjs/operators'; | ||
|
||
it('should infer correctly', () => { | ||
const o = of(1, 2, 3).pipe(expand(value => of(value))); // $ExpectType Observable<number> | ||
const p = of(1, 2, 3).pipe(expand(value => [value])); // $ExpectType Observable<number> | ||
const q = of(1, 2, 3).pipe(expand(value => Promise.resolve(value))); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should infer correctly specifying value argument type', () => { | ||
const o = of(1).pipe(expand((value: number | string) => of(value.toString()))); // $ExpectType Observable<string | number> | ||
}); | ||
|
||
it('should infer correctly with specifying different input/output types', () => { | ||
const o = of(1).pipe(expand<number, string>((value) => of(value.toString()))); // $ExpectType Observable<string | number> | ||
}); | ||
|
||
it('should enforce project output type to be assignable with its generic', () => { | ||
const o = of(1).pipe(expand<number, string>((value) => of(value))); // $ExpectError | ||
}); | ||
|
||
it('should enforce project input type to be assignable with upstream', () => { | ||
const o = of(1).pipe(expand((value: string) => of(value))); // $ExpectError | ||
}); | ||
|
||
it('should enforce project input/output types compatibility by default', () => { | ||
const o = of(1).pipe(expand((value) => of(value.toString()))); // $ExpectError | ||
}); | ||
|
||
it('should support a project function with index', () => { | ||
const o = of(1, 2, 3).pipe(expand((value, index) => of(index))); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should support concurrent parameter', () => { | ||
const o = of(1, 2, 3).pipe(expand(value => of(1), 47)); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should support a scheduler', () => { | ||
const o = of(1, 2, 3).pipe(expand(value => of(1), 47, asyncScheduler)); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should enforce types', () => { | ||
const o = of(1, 2, 3).pipe(expand()); // $ExpectError | ||
}); | ||
|
||
it('should enforce project types', () => { | ||
const o = of(1, 2, 3).pipe(expand((value: string, index) => of(1))); // $ExpectError | ||
const p = of(1, 2, 3).pipe(expand((value, index: string) => of(1))); // $ExpectError | ||
}); | ||
|
||
it('should enforce project return type', () => { | ||
const o = of(1, 2, 3).pipe(expand(value => 1)); // $ExpectError | ||
}); | ||
|
||
it('should enforce concurrent type', () => { | ||
const o = of(1, 2, 3).pipe(expand(value => of(1), 'foo')); // $ExpectError | ||
}); | ||
|
||
it('should enforce scheduler type', () => { | ||
const o = of(1, 2, 3).pipe(expand(value => of(1), 47, 'foo')); // $ExpectError | ||
}); | ||
|
||
it('should support union types', () => { | ||
const o = of(1).pipe(expand<string | number>(x => typeof x === 'string' ? of(123) : of('test'))); // $ExpectType Observable<string | number> | ||
}); |
This file contains 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
This file contains 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
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.
This should work without the explicit typing. This seems like a regression.
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.
It works without explicit typings, it’s just a test case