This file contains 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
// abstract: don't allow direct instantiation | |
abstract class BaseTable<T> { | |
// model holds the schema | |
protected model: T; | |
// convert kebab_case to camelCase | |
private camelCase(key: string) { | |
return key.replace(/_(\w)/g, function (...captures: string[]) { | |
return captures[1].toUpperCase(); | |
}); |
This file contains 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
const Fs = require('fs'); | |
const Path = require('path'); | |
const files = []; | |
const nodeModules = {}; | |
const getFilesAndSubdirectories = (dir) => { | |
Fs.readdirSync(dir) | |
.forEach((item) => { |
This file contains 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
interface MyComponentProps { | |
name: string; | |
countryCode?: string; | |
userStore: UserStore; // made required | |
router: InjectedRouter; // made required | |
} | |
... | |
class OtherComponent extends React.Component<{}, {}> { |
This file contains 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
import * as React from "react"; | |
interface MyComponentProps { | |
name: string; | |
countryCode?: string; | |
} | |
class MyComponent extends React.Component<MyComponentProps, {}> { | |
render() { | |
const { name, countryCode } = this.props; |
This file contains 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
import * as React from "react"; | |
import { inject, observer } from "mobx-react"; | |
import { withRouter, InjectedRouter } from "react-router"; | |
import { UserStore } from "../../stores/UserStore"; | |
interface MyComponentProps { | |
name: string; | |
countryCode?: string; | |
userStore?: UserStore; |
This file contains 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
interface InjectedProps extends MyComponentProps { | |
params: RouterParams; | |
} | |
interface RouterParams { | |
name: string; | |
id: number; // nope | |
} |
This file contains 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
let s1: string; | |
s1 = "some string"; | |
s1 = undefined; // Type 'undefined' is not assignable to type 'string' | |
s1 = null; // Type 'null' is not assignable to type 'string' | |
let s2: string | undefined; | |
s2 = "another string"; | |
s2 = undefined; | |
s2 = null; // Type 'null' is not assignable to type 'string | undefined' |
This file contains 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
let s: string; | |
s = "some string"; | |
s = null; | |
s = undefined; |
This file contains 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
@inject("userStore") | |
@withRouter | |
@observer | |
class MyComponent extends React.Component<MyComponentProps, {}> { | |
get injected() { | |
return this.props as InjectedProps; | |
} | |
render() { | |
const { name, countryCode } = this.props; |
This file contains 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
interface MyComponentProps { | |
name: string; | |
countryCode?: string; | |
} | |
interface InjectedProps extends MyComponentProps { | |
userStore: UserStore; | |
router: InjectedRouter; | |
} |