Skip to content

Instantly share code, notes, and snippets.

View StJohn3D's full-sized avatar
🏠
Working from home

St John Peaster StJohn3D

🏠
Working from home
View GitHub Profile
@StJohn3D
StJohn3D / Omit.ts
Created June 17, 2019 13:33
Get subtype from an existing type/interface by omitting one or more properties.
/**
* Get subtype from an existing type/interface by omitting one or more properties.
*
* **Usage:**
* ```ts
* type TSubType = Omit<IOriginalType, 'Prop1' | 'Prop2'> // IOriginalType without Prop1 and Prop2
* ```
*/
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
@StJohn3D
StJohn3D / cheerio-react.js
Created May 19, 2016 15:53
Quickly convert react components to jQuery like Cheerio objects for testing - source code from cheerio-react on npm
var ReactDOMServer = require('react-dom/server');
var cheerio = require('cheerio');
module.exports = function( reactClass ) {
var staticMarkup = ReactDOMServer.renderToStaticMarkup(reactClass);
var $ = cheerio.load(staticMarkup);
return $.root().children().first();
};