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

Upgrade to TS 2.1 #492

Merged
merged 10 commits into from
Jan 24, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"gulp-strip-css-comments": "1.2.0",
"gulp-stylelint": "3.4.0",
"gulp-tslint": "7.0.1",
"gulp-typescript": "3.0.2",
"gulp-typescript": "3.1.4",
"gulp-util": "3.0.7",
"highlights": "1.4.1",
"http-server": "0.9.0",
Expand Down Expand Up @@ -97,7 +97,7 @@
"ts-quick-docs": "0.4.0",
"tslint": "4.0.1",
"tslint-react": "2.0.0",
"typescript": "2.0.10",
"typescript": "2.1.5",
"vinyl-source-stream": "1.1.0",
"webpack": "1.13.2"
},
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/common/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import * as React from "react";

import { Intent } from "./intent";
import { shallowClone } from "./utils";

export type HTMLInputProps = React.HTMLProps<HTMLInputElement>;

Expand Down Expand Up @@ -104,7 +103,12 @@ const INVALID_PROPS = [
* @param {string[]} invalidProps If supplied, overwrites the default blacklist.
* @param {boolean} shouldMerge If true, will merge supplied invalidProps and blacklist together.
*/
export function removeNonHTMLProps<T extends U, U>(props: T, invalidProps = INVALID_PROPS, shouldMerge = false): U {
export function removeNonHTMLProps(
props: { [key: string]: any },
invalidProps = INVALID_PROPS,
shouldMerge = false,
): { [key: string]: any } {

if (shouldMerge) {
invalidProps = invalidProps.concat(INVALID_PROPS);
}
Expand All @@ -114,5 +118,5 @@ export function removeNonHTMLProps<T extends U, U>(props: T, invalidProps = INVA
delete (prev as any)[curr];
}
return prev;
}, shallowClone(props));
}, { ...props });
}
11 changes: 0 additions & 11 deletions packages/core/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,6 @@ export function clamp(val: number, min: number, max: number) {
return Math.min(Math.max(val, min), max);
}

/** Return a new object with the same keys as the given object (values are copied, not cloned). */
export function shallowClone<T>(object: T): T {
const clonedObject: any = {};
for (const key in object) {
if (object.hasOwnProperty(key)) {
clonedObject[key] = (<any> object)[key];
}
}
return clonedObject as T;
}

/**
* Throttle an event on an EventTarget by wrapping it in `requestAnimationFrame` call.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

* Returns the event handler that was bound to given eventName so you can clean up after yourself.
Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/components/toast/toaster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { TOASTER_INLINE_WARNING } from "../../common/errors";
import { ESCAPE } from "../../common/keys";
import { Position } from "../../common/position";
import { IProps } from "../../common/props";
import { safeInvoke, shallowClone } from "../../common/utils";
import { safeInvoke } from "../../common/utils";
import { Overlay } from "../overlay/overlay";
import { IToastProps, Toast } from "./toast";

Expand Down Expand Up @@ -178,9 +178,7 @@ export class Toaster extends AbstractComponent<IToasterProps, IToasterState> imp

private createToastOptions(props: IToastProps, key = `toast-${this.toastId++}`) {
// clone the object before adding the key prop to avoid leaking the mutation
const options = shallowClone<IToastOptions>(props);
options.key = key;
return options;
return { ...props, key };
}

private getPositionClasses() {
Expand Down
4 changes: 1 addition & 3 deletions packages/datetime/src/timePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ export class TimePicker extends React.Component<ITimePickerProps, ITimePickerSta
// no new value, this means only text has changed (from user typing)
// we want inputs to change, so update state with new text for the inputs
// but don't change actual value
const clonedNewState = BlueprintUtils.shallowClone(newState);
clonedNewState.value = DateUtils.clone(this.state.value);
this.setState(clonedNewState);
this.setState({ ...newState, value: DateUtils.clone(this.state.value) });
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/landing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"style-loader": "0.13.1",
"svgo": "0.7.1",
"ts-loader": "0.8.2",
"typescript": "2.0.10",
"typescript": "2.1.5",
"webpack": "1.13.3"
},
"keywords": [
Expand Down
6 changes: 3 additions & 3 deletions packages/table/examples/tableEditableExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ export class TableEditableExample extends BaseExample<{}> {
}

private setSparseState<T>(stateKey: string, dataKey: string, value: T) {
const values = Object.assign({}, (this.state as any)[stateKey]) as {[key: string]: T};
values[dataKey] = value;
this.setState({ [stateKey] : values });
const stateData = (this.state as any)[stateKey] as { [key: string]: T };
const values = { ...stateData, [dataKey]: value };
this.setState({ [stateKey]: values });
}
}
2 changes: 1 addition & 1 deletion packages/table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"react-addons-test-utils": "15.4.0",
"react-dom": "15.4.0",
"style-loader": "0.13.1",
"typescript": "2.0.10",
"typescript": "2.1.5",
"webpack": "1.13.3"
},
"repository": {
Expand Down
Loading