Skip to content

Commit

Permalink
fix(ts-typings): allow renderCallback to pass props via args (#1049)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hotell committed Jan 27, 2017
1 parent 3c97849 commit dac2c54
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ts-typings/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export class Component<Props> extends HTMLElement {

// SkateJS life cycle
updatedCallback(previousProps: { [nameOrSymbol: string]: any }): boolean | void;
renderCallback(): VDOMElement<any> | VDOMElement<any>[] | null;
// NOTE: infering generics work only on instances, not on implementation type. So this will not give you type safety, you still have to manually annotate those props in your code
renderCallback(props?:Props): VDOMElement<any> | VDOMElement<any>[] | null;
renderedCallback(): void;

// SkateJS DEPRECATED
Expand Down
21 changes: 21 additions & 0 deletions test/definitions/sample-component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as skate from "skatejs";
import { Component, prop } from 'skatejs';

// @TODO this override is needed because of https://github.com/Microsoft/TypeScript/pull/12488 will be fixed in TS 2.2
(window as any).__extends = function(d: any, b: any) {
Expand Down Expand Up @@ -59,6 +60,26 @@ export class CountUpComponent extends skate.Component<CountUpProps> {
}
customElements.define(CountUpComponent.is, CountUpComponent);

type SkateParkProps = { year: number, halfPipe: boolean }
class SkatePark extends Component<SkateParkProps>{
static get is() { return 'my-skate-park' }
static get props(): skate.ComponentProps<SkatePark, SkateParkProps> {
return {
year: prop.number(),
halfPipe: prop.boolean(),
}
}
renderCallback({halfPipe,year}:SkateParkProps) {
const halfPipeInfo = <span>{halfPipe ? 'has' : 'doesnt have'}</span>;
return (
<div>
<p>Skate park exists since {year} and it {halfPipe} Half-Pipe</p>
</div>
)
}
}
customElements.define(SkatePark.is, SkatePark);

customElements.define("x-app", class extends skate.Component<{}> {
renderCallback() {
return (
Expand Down

0 comments on commit dac2c54

Please sign in to comment.