Skip to content
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(pluck): fix pluck's catch-all signature for better type safety #5192

Merged
merged 3 commits into from Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion spec-dtslint/operators/pluck-spec.ts
@@ -1,4 +1,4 @@
import { of } from 'rxjs';
import { of, Observable } from 'rxjs';
import { pluck } from 'rxjs/operators';

it('should infer correctly', () => {
Expand Down Expand Up @@ -41,6 +41,10 @@ it('should accept string only', () => {
const a = of({ name: 'abc' }).pipe(pluck(1)); // $ExpectError
});

it('should not infer type from the variable if key doesn\'t exist', () => {
const a: Observable<number> = of({ name: 'abc' }).pipe(pluck('xyz')); // $ExpectError
Lonelind marked this conversation as resolved.
Show resolved Hide resolved
});

it('should accept a spread of arguments', () => {
const obj = {
foo: {
Expand Down
4 changes: 2 additions & 2 deletions src/internal/operators/pluck.ts
Expand Up @@ -9,8 +9,8 @@ export function pluck<T, K1 extends keyof T, K2 extends keyof T[K1], K3 extends
export function pluck<T, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(k1: K1, k2: K2, k3: K3, k4: K4): OperatorFunction<T, T[K1][K2][K3][K4]>;
export function pluck<T, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4]>(k1: K1, k2: K2, k3: K3, k4: K4, k5: K5): OperatorFunction<T, T[K1][K2][K3][K4][K5]>;
export function pluck<T, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4], K6 extends keyof T[K1][K2][K3][K4][K5]>(k1: K1, k2: K2, k3: K3, k4: K4, k5: K5, k6: K6): OperatorFunction<T, T[K1][K2][K3][K4][K5][K6]>;
export function pluck<T, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4], K6 extends keyof T[K1][K2][K3][K4][K5], R>(k1: K1, k2: K2, k3: K3, k4: K4, k5: K5, k6: K6, ...rest: string[]): OperatorFunction<T, R>;
export function pluck<T, R= unknown>(...properties: string[]): OperatorFunction<T, R>;
export function pluck<T, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4], K6 extends keyof T[K1][K2][K3][K4][K5]>(k1: K1, k2: K2, k3: K3, k4: K4, k5: K5, k6: K6, ...rest: string[]): OperatorFunction<T, unknown>;
export function pluck<T>(...properties: string[]): OperatorFunction<T, unknown>;
/* tslint:enable:max-line-length */

/**
Expand Down