Last active
June 12, 2019 21:00
-
-
Save bultas/f225502591c3ede59445758528d20dd3 to your computer and use it in GitHub Desktop.
Type Safe without TypeScript - https://github.com/Microsoft/TypeScript/wiki/JsDoc-support-in-JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {HTMLFunction} html | |
* @returns {(instance: Instance) => (number) => string} | |
*/ | |
const template = html => instance => multiplier => html` | |
<h1>Hello ${instance.data.name}</h1> | |
<h2>count: ${2 * multiplier}</h2> | |
`; | |
/** | |
* @param {Instance} instance | |
* @returns {Promise<string>} | |
*/ | |
const render = async instance => template(html)(instance)(4); | |
export default render; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @ts-check | |
/** | |
* @typedef {object} BrowserHistory | |
* @property {(route: string) => void} push | |
*/ | |
/** | |
* @param {BrowserHistory} history | |
* @returns {(route: string) => void} | |
*/ | |
const push = history => route => history.push(route); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @type {Template} */ | |
const template = html => instance => html` | |
<script type="module" src="${instance.app.static_url}/script.js"></script> | |
<h1>Hello World</h1> | |
`; | |
/** | |
* @param {Instance} instance | |
* @returns {Promise<string>} | |
*/ | |
const render = async instance => template(html)(instance); | |
export default render; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"compilerOptions": { | |
"target": "es6", | |
"checkJs": true | |
}, | |
"exclude": [ | |
"node_modules", | |
"**/node_modules/*" | |
], | |
// "include": [ | |
// "index.js", | |
// "types.js" | |
// ] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @typedef {object} RequestData | |
* @property {Object<string, any>} query_params | |
* @property {array} path_info | |
*/ | |
/** | |
* @typedef {object} AppData | |
* @property {string} static_url | |
*/ | |
/** | |
* @typedef {object} ConfigData | |
* @property {string} api_url | |
*/ | |
/** | |
* @typedef {object} PageData | |
* @property {string} name | |
* @property {string} id | |
* @property {Object<string, any>} db | |
*/ | |
/** | |
* @typedef {object} Instance | |
* @property {RequestData} request | |
* @property {AppData} app | |
* @property {ConfigData} config | |
* @property {PageData} data | |
*/ | |
/** | |
* @callback HTMLFunction | |
* @param {TemplateStringsArray} string | |
* @param {any} any | |
* @returns {string} | |
*/ | |
/** | |
* @callback Template | |
* @param {HTMLFunction} html | |
* @returns {(instance: Instance) => string} | |
*/ |
ale pres CL ./node_modules/.bin/tsc --checkJs --target ES2016
to je jiz v poradku
@s-m-i-t-a toto funguje ...
/**
* @callback Template
* @param {HTMLFunction} html
* @returns {(instance: Instance) => (something: string) => string}
*/
/**
* @type {Template}
*/
const template = html => instance => something => html`
<script type="module" src="${instance.app.static_url}/script.js"></script>
<h1>Hello World</h1>
`;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
problem with async and arrow functions
fixed by removing arrow function