Skip to content

Commit

Permalink
minor typing improvements, see #672
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Nov 25, 2016
1 parent 66fdf7a commit fafea75
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/api/observe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {IObservableValue} from "../types/observablevalue";
import {Lambda} from "../utils/utils";
import {getAdministration} from "../types/type-utils";

export function observe<T>(value: IObservableValue<T> | IComputedValue<T>, listener: (newValue: T, oldValue: T) => void, fireImmediately?: boolean): Lambda;
export function observe<T>(value: IObservableValue<T> | IComputedValue<T>, listener: (newValue: T, oldValue: T | undefined) => void, fireImmediately?: boolean): Lambda;
export function observe<T>(observableArray: IObservableArray<T>, listener: (change: IArrayChange<T> | IArraySplice<T>) => void, fireImmediately?: boolean): Lambda;
export function observe<T>(observableMap: ObservableMap<T>, listener: (change: IMapChange<T>) => void, fireImmediately?: boolean): Lambda;
export function observe<T>(observableMap: ObservableMap<T>, property: string, listener: (newValue: T, oldValue: T) => void, fireImmediately?: boolean): Lambda;
export function observe<T>(observableMap: ObservableMap<T>, property: string, listener: (newValue: T, oldValue: T | undefined) => void, fireImmediately?: boolean): Lambda;
export function observe(object: Object, listener: (change: IObjectChange) => void, fireImmediately?: boolean): Lambda;
export function observe(object: Object, property: string, listener: (newValue: any, oldValue: any) => void, fireImmediately?: boolean): Lambda;
export function observe(object: Object, property: string, listener: (newValue: any, oldValue: any | undefined) => void, fireImmediately?: boolean): Lambda;
export function observe(thing, propOrCb?, cbOrFire?, fireImmediately?): Lambda {
if (typeof cbOrFire === "function")
return observeObservableProperty(thing, propOrCb, cbOrFire, fireImmediately);
Expand Down
5 changes: 2 additions & 3 deletions src/api/whyrun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {globalState} from "../core/globalstate";
import {isComputedValue} from "../core/computedvalue";
import {isReaction} from "../core/reaction";
import {getAtom} from "../types/type-utils";
import {invariant, deprecated} from "../utils/utils";
import {fail, deprecated} from "../utils/utils";

function log(msg: string): string {
console.log(msg);
Expand All @@ -26,6 +26,5 @@ export function whyRun(thing?: any, prop?: string) {
return log(thing.whyRun());
else if (isReaction(thing))
return log(thing.whyRun());
else
invariant(false, "whyRun can only be used on reactions and computed values");
return fail("whyRun can only be used on reactions and computed values");
}
2 changes: 1 addition & 1 deletion src/core/spy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function isSpyEnabled() {

export function spyReport(event) {
if (!globalState.spyListeners.length)
return false;
return;
const listeners = globalState.spyListeners;
for (let i = 0, l = listeners.length; i < l; i++)
listeners[i](event);
Expand Down
4 changes: 2 additions & 2 deletions src/types/observablearray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,11 @@ export class ObservableArray<T> extends StubArray {
return adm.values.length;
}

pop(): T {
pop(): T | undefined {
return this.splice(Math.max(this.$mobx.values.length - 1, 0), 1)[0];
}

shift(): T {
shift(): T | undefined {
return this.splice(0, 1)[0];
}

Expand Down
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"declaration": true,
"module": "commonjs",
"removeComments": false,
"strictNullChecks": true
"strictNullChecks": true,
"noImplicitReturns": true,
"noImplicitUseStrict": true,
"noImplicitAny": false // but should be true for all publicly exposed things!
},
"exclude": [
"node_modules",
Expand Down

0 comments on commit fafea75

Please sign in to comment.