Skip to content

Commit

Permalink
TSLint: handle errors in kbn_internal_native_observable types. (#20705)
Browse files Browse the repository at this point in the history
  • Loading branch information
azasypkin committed Jul 12, 2018
1 parent da1acd0 commit 875008a
Showing 1 changed file with 100 additions and 85 deletions.
185 changes: 100 additions & 85 deletions src/core/lib/kbn_internal_native_observable/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

// This adds a symbol type for `Symbol.observable`, which doesn't exist globally
// in TypeScript yet.
declare global {
Expand All @@ -10,111 +29,107 @@ declare global {
// https://github.com/tc39/proposal-observable#api, with the addition of using
// generics to define the type of the `value`.

declare namespace Observable {
interface Subscription {
// Cancels the subscription
unsubscribe(): void;
interface Subscription {
// A boolean value indicating whether the subscription is closed
closed: boolean;

// A boolean value indicating whether the subscription is closed
closed: boolean;
}
// Cancels the subscription
unsubscribe(): void;
}

interface Subscribable<T> {
subscribe(
observerOrNext?: SubscriptionObserver<T> | ((value: T) => void),
error?: (error: any) => void,
complete?: () => void
): Subscription;
}
interface Subscribable<T> {
subscribe(
observerOrNext?: SubscriptionObserver<T> | ((value: T) => void),
error?: (error: any) => void,
complete?: () => void
): Subscription;
}

type ObservableInput<T> = Subscribable<T> | Iterable<T>;
type ObservableInput<T> = Subscribable<T> | Iterable<T>;

interface SubscriptionObserver<T> {
// Sends the next value in the sequence
next(value: T): void;
interface SubscriptionObserver<T> {
// A boolean value indicating whether the subscription is closed
closed: boolean;

// Sends the sequence error
error(errorValue: Error): void;
// Sends the next value in the sequence
next(value: T): void;

// Sends the completion notification
complete(): void;
// Sends the sequence error
error(errorValue: Error): void;

// A boolean value indicating whether the subscription is closed
closed: boolean;
}
// Sends the completion notification
complete(): void;
}

export interface StartObserver<T> {
start(subscription: Subscription): void;
next?(value: T): void;
error?(err: any): void;
complete?(): void;
}
export interface StartObserver<T> {
start(subscription: Subscription): void;
next?(value: T): void;
error?(err: any): void;
complete?(): void;
}

export interface NextObserver<T> {
start?(subscription: Subscription): void;
next(value: T): void;
error?(err: any): void;
complete?(): void;
}
export interface NextObserver<T> {
start?(subscription: Subscription): void;
next(value: T): void;
error?(err: any): void;
complete?(): void;
}

interface ErrorObserver<T> {
start?(subscription: Subscription): void;
next?(value: T): void;
error(err: any): void;
complete?(): void;
}
interface ErrorObserver<T> {
start?(subscription: Subscription): void;
next?(value: T): void;
error(err: any): void;
complete?(): void;
}

interface CompletionObserver<T> {
start?(subscription: Subscription): void;
next?(value: T): void;
error?(err: any): void;
complete(): void;
}
interface CompletionObserver<T> {
start?(subscription: Subscription): void;
next?(value: T): void;
error?(err: any): void;
complete(): void;
}

type PartialObserver<T> =
| StartObserver<T>
| NextObserver<T>
| ErrorObserver<T>
| CompletionObserver<T>;
type PartialObserver<T> =
| StartObserver<T>
| NextObserver<T>
| ErrorObserver<T>
| CompletionObserver<T>;

interface Observer<T> {
// Receives the subscription object when `subscribe` is called
start(subscription: Subscription): void;
interface Observer<T> {
// Receives the subscription object when `subscribe` is called
start(subscription: Subscription): void;

// Receives the next value in the sequence
next(value: T): void;
// Receives the next value in the sequence
next(value: T): void;

// Receives the sequence error
error(errorValue: Error): void;
// Receives the sequence error
error(errorValue: Error): void;

// Receives a completion notification
complete(): void;
}
// Receives a completion notification
complete(): void;
}

type SubscriberFunction<T> = (
observer: SubscriptionObserver<T>
) => void | null | undefined | (() => void) | Subscription;
type SubscriberFunction<T> = (
observer: SubscriptionObserver<T>
) => void | null | undefined | (() => void) | Subscription;

class Observable<T> {
constructor(subscriber: SubscriberFunction<T>);
export class Observable<T> {
public static of<T>(...items: T[]): Observable<T>;
public static from<T>(x: ObservableInput<T>): Observable<T>;

// Subscribes to the sequence with an observer
subscribe(): Subscription;
subscribe(observer: PartialObserver<T>): Subscription;
constructor(subscriber: SubscriberFunction<T>);

// Subscribes to the sequence with callbacks
subscribe(
onNext: (val: T) => void,
onError?: (err: Error) => void,
onComplete?: () => void
): Subscription;
// Subscribes to the sequence with an observer
public subscribe(): Subscription;
public subscribe(observer: PartialObserver<T>): Subscription;

// Returns itself
[Symbol.observable](): Observable<T>;
// Subscribes to the sequence with callbacks
public subscribe(
onNext: (val: T) => void,
onError?: (err: Error) => void,
onComplete?: () => void
): Subscription;

static of<T>(...items: T[]): Observable<T>;
static from<T>(x: ObservableInput<T>): Observable<T>;
}
// Returns itself
public [Symbol.observable](): Observable<T>;
}

export = Observable;

0 comments on commit 875008a

Please sign in to comment.