Skip to content

Commit

Permalink
fix(ts-typings): make define generic so it returns proper constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Hotell committed Jan 25, 2017
1 parent 08aae26 commit d8c6fcf
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/ts-typings/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,17 @@ export interface PropOptions<El, T> {
set?: (elem: El, data: { name: string; newValue: T | null | undefined; oldValue: T | null | undefined; }) => void;
}

export var define: {
(name: string, ctor: Function): any;
(ctor: Function): any;
};
interface Define {
<T extends Partial<HTMLElement>>(ctor: T): T;
/**
* @Deprecated - will be removed in 5.0
*/
<T extends Partial<HTMLElement>>(name: string, ctor: T): T;
}
/**
* The define() function is syntactic sugar on top of customElements.define() that allows you to specify a static is property on your constructor that is the name of the component, or omit it altogether.
*/
export var define: Define;

export interface EmitOptions {
bubbles?: boolean;
Expand Down
42 changes: 42 additions & 0 deletions test/definitions/misc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,48 @@
}
{ // https://github.com/skatejs/skatejs#renderedcallback---supersedes-static-rendered
// NONE
}
{
// https://skatejs.gitbooks.io/skatejs/content/docs/api/define.html

const Ctor1 = skate.define(class extends HTMLElement {
static is = 'x-test-1';
private _who: string;
get who() { return this._who }
set who(val) { this._who = val }
});

const pureElemenInst = new Ctor1();
console.log(pureElemenInst.who);

const Ctor2 = skate.define(class extends HTMLElement {
static is = 'x-test-2'
});

const SkateCtor = skate.define(class extends skate.Component<{ who: string }>{
static get is() { return 'my-skate' }
static get props() {
return {
who: skate.prop.string()
}
}
who: string
});

const skElementInst = new SkateCtor();
console.log(skElementInst.who);

// @Deprecated
const SkateCtor2 = skate.define('my-skate', class SkateCmp2 extends skate.Component<{ who: string }>{
static get props() {
return {
who: skate.prop.string()
}
}
who: string
});


}
{ // https://github.com/skatejs/skatejs#emit-elem-eventname-eventoptions--
customElements.define('x-tabs', class extends skate.Component<any> {
Expand Down

0 comments on commit d8c6fcf

Please sign in to comment.