Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Commit

Permalink
Fix compatibility with TS 1.6 object literal typing
Browse files Browse the repository at this point in the history
TS 1.6 requires that object literals assigned
to variables or parameters with an interface typing
may only contain properties that are listed in the interface.

See microsoft/TypeScript#3823
for details.

This mostly affected React component props interfaces
which did not extend react.Props so were missing the common
key, ref and children props.
  • Loading branch information
robertknight committed Aug 16, 2015
1 parent 1808566 commit a1bc33b
Show file tree
Hide file tree
Showing 20 changed files with 58 additions and 59 deletions.
2 changes: 0 additions & 2 deletions lib/agile_keychain_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ testLib.addAsyncTest('Import item from .1pif file', (assert) => {
actualItems.then((items) => {
assert.equal(items.length, 1, 'Imported expected number of items');
var expectedItem = agile_keychain.fromAgileKeychainItem(null, {
"vault": null,
"updatedAt": 1398413120,
"title": "Facebook",
"securityLevel": "SL5",
Expand Down Expand Up @@ -725,4 +724,3 @@ testLib.addAsyncTest('Removing item succeeds if file is already removed', assert
assert.ok(testVault.items[0].isTombstone());
});
});

6 changes: 2 additions & 4 deletions lib/siteinfo/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ import url_util = require('../base/url_util');
// list of known <link> and <meta> tags that point
// to an icon for the site.
//
// See also:
// See also:
// - http://microformats.org/wiki/existing-rel-values (list of known
// values for 'rel' attribute of <link> tags)
// - http://www.iacquire.com/blog/18-meta-tags-every-webpage-should-have-in-2013
// - Google structured data testing tool: http://www.google.com/webmasters/tools/richsnippets
//
//

export enum MetaTagType {
Meta,
Expand Down Expand Up @@ -265,7 +265,6 @@ export class SiteInfoService implements site_info.SiteInfoProvider {
var result: site_info.QueryResult = {
info: {
url: url,
iconUrl: null,
icons: []
},
state: site_info.QueryState.Updating
Expand Down Expand Up @@ -597,4 +596,3 @@ export class DuckDuckGoClient {
}
}
}

3 changes: 1 addition & 2 deletions lib/vfs/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class FileVFS implements vfs.VFS {
}

login(): Q.Promise<vfs.Credentials> {
return Q<vfs.Credentials>({ user: process.env.USER });
return Q<vfs.Credentials>({});
}

isLoggedIn(): boolean {
Expand Down Expand Up @@ -247,4 +247,3 @@ export class FileVFS implements vfs.VFS {
return fullPath;
}
}

3 changes: 2 additions & 1 deletion typings/argparse.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ declare module "argparse" {
nargs? : any; // number or string
type? : string;
defaultValue? : any;
help?: string;
choices?: string[];
}

export interface Subparsers {
Expand All @@ -25,4 +27,3 @@ declare module "argparse" {
parseArgs(args?: string[]) : any;
}
}

7 changes: 3 additions & 4 deletions webui/app_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface AppServices {
fs: vfs.VFS;
}

export interface AppViewProps {
export interface AppViewProps extends react.Props<void> {
services: AppServices;
viewportRect: reactutil.Rect;
itemStore: ui_item_store.Store;
Expand Down Expand Up @@ -160,7 +160,7 @@ class AppView extends typed_react.Component<AppViewProps, AppViewState> {
children.push(this.renderItemDetails());
children.push(this.renderToasters());

var menu = reactutil.TransitionGroupF({ key: 'toolbar-menu' },
var menu = reactutil.TransitionGroupF(<any>{ key: 'toolbar-menu' },
this.state.appMenuSourceRect ? this.renderMenu('menu') : null
);
children.push(menu);
Expand Down Expand Up @@ -189,7 +189,7 @@ class AppView extends typed_react.Component<AppViewProps, AppViewState> {
progressMax: syncState.total
}));
}
return reactutil.TransitionGroupF({ key: 'toasterList' },
return reactutil.TransitionGroupF(<any>{ key: 'toasterList' },
toasters
);
}
Expand Down Expand Up @@ -376,4 +376,3 @@ class AppView extends typed_react.Component<AppViewProps, AppViewState> {
}

export var AppViewF = reactutil.createFactory(AppView);

12 changes: 11 additions & 1 deletion webui/base/reactutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ import env = require('../../lib/base/env');
import transition_events = require('./transition_events');
import tsutil = require('../../lib/base/tsutil');

/** Extends the CSSProperties interface which as of 16/08/15
* only lists a small subset of CSS properties with one with
* a catch-all for other properties.
*
* See also https://github.com/borisyankov/DefinitelyTyped/pull/5089 for
* a discussion on how best to resolve this upstream.
*/
export interface ExtendedCSSProperties extends react.CSSProperties {
[index: string]: number | string;
}

/** Component factory returned by createFactory(). This extends
* React.Factory with an additional property that specifies the
* type of component which the factory creates.
Expand Down Expand Up @@ -179,4 +190,3 @@ export class TransitionEndListener {
transition_events.removeEndEventListener(this.node, this.listener);
}
}

9 changes: 7 additions & 2 deletions webui/base/reactutil_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
import reactutil = require('./reactutil');
import testLib = require('../../lib/test');

interface PropMergeResult {
id?: string;
className?: string;
onClick?: string;
};

testLib.addTest('merge props', (assert) => {
assert.deepEqual(reactutil.mergeProps({
assert.deepEqual<PropMergeResult>(reactutil.mergeProps({
id: 'instanceId',
className: 'instanceClass',
onClick: 'event handler'
Expand Down Expand Up @@ -34,4 +40,3 @@ testLib.addTest('object changes', (assert) => {
});

testLib.start();

5 changes: 1 addition & 4 deletions webui/controls/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export enum Style {
Icon
}

export interface ButtonProps {
export interface ButtonProps extends react.Props<void> {
onClick: (e: react.MouseEvent) => void;

/** Label for the button */
Expand All @@ -177,8 +177,6 @@ export interface ButtonProps {

/** Prevents interaction with the button */
disabled?: boolean;

children?: any;
}

export class Button extends typed_react.Component<ButtonProps, {}> {
Expand Down Expand Up @@ -295,4 +293,3 @@ export class Button extends typed_react.Component<ButtonProps, {}> {
}

export var ButtonF = reactutil.createFactory(Button);

3 changes: 1 addition & 2 deletions webui/controls/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var theme = style.create({
}
});

interface ControlDemoAppProps {
interface ControlDemoAppProps extends react.Props<void> {
viewportRect: reactutil.Rect;
}

Expand Down Expand Up @@ -203,4 +203,3 @@ function main() {
if (env.isBrowser()) {
main();
}

5 changes: 2 additions & 3 deletions webui/controls/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var theme = style.create({
label: {
width: '100%',
height: '100%',

// give menu item label its own stacking context so
// that it renders on top of ripple effect
transform: 'translate3d(0,0,0)'
Expand All @@ -97,7 +97,7 @@ interface MenuState {
showTime?: Date;
}

export interface MenuProps {
export interface MenuProps extends react.Props<void> {
/** The source rect of the icon which triggered the
* menu.
*/
Expand Down Expand Up @@ -369,4 +369,3 @@ export class Menu extends typed_react.Component<MenuProps, MenuState> {
}

export var MenuF = reactutil.createFactory(Menu);

5 changes: 2 additions & 3 deletions webui/controls/ripple.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference path="../../typings/react.d.ts" />

// Material Design style touch-ripple.
// See https://www.polymer-project.org/docs/elements/paper-elements.html#paper-ripple
// See https://www.polymer-project.org/docs/elements/paper-elements.html#paper-ripple

import react = require('react');
import style = require('ts-style');
Expand Down Expand Up @@ -38,7 +38,7 @@ enum Phase {
Release
}

export interface InkRippleProps {
export interface InkRippleProps extends react.Props<void> {
/** Fill style for the expanding ripple.
* The background of the ripple uses a lighter version of
* this color.
Expand Down Expand Up @@ -259,4 +259,3 @@ export class InkRipple extends typed_react.Component<InkRippleProps, InkRippleSt
}
}
export var InkRippleF = reactutil.createFactory(InkRipple);

7 changes: 5 additions & 2 deletions webui/controls/svg_icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import underscore = require('underscore');

import reactutil = require('../base/reactutil');

export class SvgIconProps {
export interface SvgIconProps extends react.Props<react.HTMLComponent>, react.HTMLAttributes {
// redeclare 'ref' here to resolve conflict between
// react.Props.ref and react.HTMLAttributes.ref
ref?: string;

href: string;
fill: string;
viewBox: {
Expand Down Expand Up @@ -35,4 +39,3 @@ export class SvgIcon extends typed_react.Component<SvgIconProps, {}> {
}

export var SvgIconF = reactutil.createFactory(SvgIcon);

3 changes: 1 addition & 2 deletions webui/controls/text_field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export interface TextFieldStyle {
fontFamily?: string;
}

export interface TextFieldProps {
export interface TextFieldProps extends react.Props<void> {
/** Specifies the type of <input> field */
type?: string;

Expand Down Expand Up @@ -414,4 +414,3 @@ export class TextField extends typed_react.Component<TextFieldProps, TextFieldSt
}

export var TextFieldF = reactutil.createFactory(TextField);

3 changes: 1 addition & 2 deletions webui/controls/toaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var theme = style.create({
}
});

export interface ToasterProps {
export interface ToasterProps extends react.Props<void> {
message: string;
progressValue?: number;
progressMax?: number;
Expand Down Expand Up @@ -97,4 +97,3 @@ export class Toaster extends typed_react.Component<ToasterProps, ToasterState> {
}

export var ToasterF = reactutil.createFactory(Toaster, transition_mixin.TransitionMixinM);

8 changes: 3 additions & 5 deletions webui/details_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ interface ItemFieldState {
value?: string;
}

interface ItemFieldProps {
interface ItemFieldProps extends react.Props<void> {
label: string;
value: string;
type: FieldType;
Expand Down Expand Up @@ -383,7 +383,7 @@ export enum ItemEditMode {
EditItem
}

export interface DetailsViewProps {
export interface DetailsViewProps extends react.Props<void> {
entryRect?: reactutil.Rect;
viewportRect: reactutil.Rect;
animateEntry: boolean;
Expand Down Expand Up @@ -972,7 +972,7 @@ export class DetailsView extends typed_react.Component<DetailsViewProps, Details
var itemListDetailsStyle: any[] = [headerTheme.iconAndDetails.details.itemList];
var detailsViewDetailsStyle: any[] = [headerTheme.iconAndDetails.details.detailsView];

var contentStyles: react.CSSProperties[] = [{
var contentStyles: reactutil.ExtendedCSSProperties[] = [{
paddingTop: 16,

// vertically align left edge of details text with item
Expand Down Expand Up @@ -1002,7 +1002,6 @@ export class DetailsView extends typed_react.Component<DetailsViewProps, Details
bottom: 16
}), button.ButtonF({
style: button.Style.FloatingAction,
accessKey: 'a',
backgroundColor: colors.MATERIAL_COLOR_PRIMARY,
color: colors.MATERIAL_COLOR_HEADER,
rippleColor: 'white',
Expand Down Expand Up @@ -1058,4 +1057,3 @@ export class DetailsView extends typed_react.Component<DetailsViewProps, Details
}

export var DetailsViewF = reactutil.createFactory(DetailsView, focus_mixin.FocusMixinM);

5 changes: 2 additions & 3 deletions webui/item_icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class BasicIconProvider implements IconProvider {
private static DEFAULT_ICON = 'dist/icons/default.png';

updated: event_stream.EventStream<string>;

/** Create an icon provider which uses @p provider to fetch
* icon data. @p iconSize specifies the size of icon to make from
* the available icons for a given URL.
Expand Down Expand Up @@ -402,7 +402,7 @@ class Cache {
}
}

export interface IconControlProps {
export interface IconControlProps extends react.Props<void> {
location: string;
iconProvider: IconProvider;
isFocused: boolean;
Expand Down Expand Up @@ -512,4 +512,3 @@ export class FakeIconProvider implements IconProvider {
}

export var IconControlF = reactutil.createFactory(IconControl);

8 changes: 4 additions & 4 deletions webui/item_list_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ interface ItemListViewState {
filter?: string;
}

export class ItemListViewProps {
export interface ItemListViewProps extends react.Props<void> {
items: item_store.Item[];
selectedItem: item_store.Item;
onSelectedItemChanged: (item: item_store.Item, rect: reactutil.Rect) => void;
Expand Down Expand Up @@ -254,7 +254,7 @@ export class ItemListView extends typed_react.Component<ItemListViewProps, ItemL

export var ItemListViewF = reactutil.createFactory(ItemListView, focus_mixin.FocusMixinM);

export interface ItemProps {
export interface ItemProps extends react.Props<void> {
key: string;
item: item_store.Item;
onSelected: () => void;
Expand Down Expand Up @@ -327,7 +327,7 @@ interface ItemListState {
itemHeight?: number;
}

class ItemListProps {
export interface ItemListProps extends react.Props<void> {
items: item_store.Item[];
filter: string;
filterUrl: string;
Expand Down Expand Up @@ -598,7 +598,7 @@ class ItemList extends typed_react.Component<ItemListProps, ItemListState> {

var ItemListF = reactutil.createFactory(ItemList);

class ItemListToolbarProps {
export interface ItemListToolbarProps extends react.Props<void> {
filterUrl: string;

onQueryChanged: (query: string) => void;
Expand Down
Loading

0 comments on commit a1bc33b

Please sign in to comment.