Skip to content

Instantly share code, notes, and snippets.

View nadeesha's full-sized avatar

Nadeesha Cabral nadeesha

View GitHub Profile
type ReturnType<T extends (...args: any[]) => any> =
T extends (...args: any[]) => infer R ? R : any;
const foo = (value: string) => {
return {
input: value,
time: Date.now(),
characters: value.split()
}
}
type FooOutput = {
input: string;
export const idx = <T extends {}, U>(
props: T,
selector: (props: T) => U | undefined
) => {
try {
return selector(props);
} catch (e) {
return undefined;
}
};
export const idx = (
props: any,
selector: (props: any) => any
) => {
try {
return selector(props);
} catch (e) {
return undefined;
}
};
type User = {
user?: {
name: string,
friends?: Array<User>,
}
};
// to safely get friends or friends, we have to write:
const friendsOfFriends =
props.user &&
const wrapInObj = <T>(myValue: T) => {
return {
value: myValue,
}
}
const wrapInObj = (myValue: any) => {
return {
value: myValue,
}
}
const wrappedValue = wrapInObj(12345);
wrappedValue.value.split(); // TypeError: wrappedValue.value.split is not a function 🤒
  • Programming with Futures

  • Render props in React

  • Basics of neural networks and Brain.js

  • How to work with RxJS

  • Bash chains and using xargs

const pipe = require("lodash/fp/pipe");
const qs = require("qs");
const getRedirectToParam = (parsedQuery) => parsedQuery.redirect_to;
const storeRedirectToQuery = (redirectTo) => {
localStorage.setItem("REDIRECT_TO", redirectTo);
return redirectTo;
};
const pipe = require("lodash/fp/pipe");
const qs = require("qs");
const getRedirectToParam = (parsedQuery) => parsedQuery.redirect_to;
const storeRedirectToQuery = (redirectTo) => {
localStorage.setItem("REDIRECT_TO", redirectTo)
return redirectTo;
};