git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git
cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git
cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
use std::io; | |
#[derive(Debug)] | |
struct BSTNode { | |
value: i32, | |
left: Option<Box<BSTNode>>, | |
right: Option<Box<BSTNode>> | |
} | |
impl BSTNode { |
#[derive(Debug, PartialEq, Eq)] | |
enum State { | |
/// There are `0`s only. | |
Empty, | |
/// There may be `1`s and `0`s. | |
Partial, | |
/// There are `1`s only. |
export function withHover<T>(WrappedComponent: React.ComponentType<T & Hoverable>): React.ComponentClass<T> { | |
return class extends React.Component<T> { | |
state = { | |
hover: false, | |
}; | |
onMouseEnter: React.MouseEventHandler = () => { | |
this.setState({ hover: true }); | |
}; |
Vuex 4 is a great companion to Vue 3, but Vuex is falling behind on Typescript support. While waiting for better typing support in Vuex 5 or using Pinia, this wrapper might help.
Using this wrapper will correctly infer arguments and return types on your state, actions, getters and mutations.
It works both within your store(s) and any Vue components where you use the mapActions
, mapState
, mapGetters
or mapMutations
helpers from Vuex.
No more any
will help you find many errors at compile-time!
//I find typescripts enums a bit lacking. | |
//This is a way to havevery strongly typed bidirectional lookup table | |
//first we start with a helper type to reverse a record with unique literal value types as property types | |
type UniqueReverser<T extends Record<keyof T, PropertyKey>> = unknown extends { | |
[K in keyof T]-?: T[K] extends Omit<T, K>[Exclude<keyof T, K>] ? unknown : never | |
}[keyof T] ? never : { [P in keyof T as T[P]]: P } | |
//this will allow to convert an object in this shape and type | |
const SOURCE = { |