Skip to content

Instantly share code, notes, and snippets.

@alihammad-gist
Last active September 6, 2015 18:36
Show Gist options
  • Save alihammad-gist/11e528adf2ce2837ef37 to your computer and use it in GitHub Desktop.
Save alihammad-gist/11e528adf2ce2837ef37 to your computer and use it in GitHub Desktop.
///<reference path="tree.d.ts"/>
///<reference path="../../typings/tsd.d.ts"/>
type ReactElement = React.ReactElement<any>
type TreeItem = Tree.Item
/*
Same function signature as Tree.ItemReactElementFactory
(which is defined in tree.d.ts - gist is below)
*/
interface ItemReactElementFactory {
(data:TreeItem): ReactElement;
}
// Local function interface works
var factory1:ItemReactElementFactory = function (data:TreeItem) :ReactElement {
return React.DOM.b({}, "hello");
};
// Function interface from tree.d.ts gives error even though both
// ItemReactElementFactory and Tree.ItemReactElementFactory have same signature
var factory2:Tree.ItemReactElementFactory = function (data:TreeItem) :ReactElement {
return React.DOM.b({}, "hello");
};
///<reference path="../../typings/tsd.d.ts"/>
declare module Tree {
import React = __React;
type ItemValue = string | number;
interface Item {
[key: string]: ItemValue | Data; // scalar ItemValue or Nested Data
}
type Data = Item[];
// This one doesn't work
interface ItemReactElementFactory {
(data:Item): React.ReactElement<any>;
}
interface OnParentChange {
(src_key:ItemValue, old_parent_key:ItemValue, new_parent_key:ItemValue): void
}
interface OnOrderChange {
(src_key:ItemValue, old_idx:number, new_idx:number): void
}
interface TreeProps {
data: Data;
factory: ItemReactElementFactory;
children_hash: string;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment