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
// without TypeScript | |
import PropTypes from 'prop-types'; | |
class Greeting extends React.Component { | |
render() { | |
return ( | |
<h1>Hello, {this.props.name}</h1> | |
); | |
} |
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
function FindProxyForURL(url, host) { | |
// If the hostname matches, use proxy. | |
if ( | |
shExpMatch(host, "*.aline.work") || | |
shExpMatch(host, "aline.work") || | |
shExpMatch(host, "*.ipify.org") | |
) { | |
return "PROXY xx.xx.xx.xx:8888"; | |
} |
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
export interface BasicUserFragment { | |
id: string, | |
first_name: string, | |
last_name: string, | |
username: string | null, | |
picture_path: string | null, | |
active: boolean, | |
portfolio_id: string | null, | |
job_title: string | null, | |
email: string, |
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'; | |
/* imports ... */ | |
import { pick } from 'lodash'; | |
class Form extends ModuleForm { | |
fields: FieldsDefinitions = { | |
id: 'none', | |
email: 'none', | |
picture_path: { | |
type: 'image', transformations: 'h_200,w_200,r_max,c_fill' |
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'; | |
/* imports ... */ | |
import { client } from '../../core/apollo'; | |
const jsonSchema: JSONSchema6 = require('./core/apollo-form-json-schema.json'); | |
// this is common for the whole application, brang here for the example. | |
const AlineSidebarForm = configure<ApolloFormMutationNames>({ | |
client, | |
jsonSchema, | |
theme: alineSidebarTheme |
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
type Mutation { | |
update_user(id: String!, user: UserInputType): User | |
} | |
input UserInputType { | |
first_name: String | |
last_name: String | |
picture_path: String | |
job_title: String | |
email: String |
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 Person { | |
name: string | |
address?: { | |
city: string | |
zipcode: string | |
} | |
} | |
function getCity(p: Person): string | undefined { | |
if (p.address) { |
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
function example(x: string | number, y: string | boolean) { | |
if (x === y) { | |
x | |
// `x` is of type `string` | |
y | |
// `y` is of type `string` | |
} else { | |
x | |
// `x` is of type `string | number` |
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 { format as fmtDate, parseISO } from 'date-fns' | |
function formatDate(date: Date | string | number, format = 'dd-mm-YYYY') { | |
let d = null | |
if (typeof date === 'string') { | |
date | |
// `date` is of type `string` | |
d = parseISO(date) |
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
function doSomething(x: string | number | boolean) { | |
const isString = typeof x === "string" | |
const isNumber = typeof x === "number" | |
const isStringOrNumber = isString || isNumber | |
if (isStringOrNumber) { | |
x | |
// `x` is of type `string | number` | |
if (typeof x === "number" && x > 0) { |