Skip to content

Instantly share code, notes, and snippets.

View quicksnap's full-sized avatar
🎮
GitHub has statuses?!

Dan Schuman quicksnap

🎮
GitHub has statuses?!
View GitHub Profile

Avoid TypeScript as assertions! Especially with return values...

Note: A satisfies operator may improve this issue. A detailed discussion of this is here: microsoft/TypeScript#47920

Using as in TypeScript is usually bad, since it can downcast your type. Example:

type Dog = { name: string; breed: string };
const puppy = { name: 'Spot' } as Dog;
getTabs = (isEventFinished: boolean) => {
const { isParticipant, isGodOrOwner: isGodOrOwnerProp } = this.props
const {
summary,
activitylog,
scorebreakdown,
participants,
leaderboard,
import * as CSS from 'csstype'
type SingleOrArray<Properties, T extends keyof Properties> = {
[P in T]: Properties[P] | Array<Properties[P]>
}
type CSSPropertiesLoosePseudo = { [K in CSS.Pseudos]?: CSSPropertiesLoose }
type CSSPropertiesPseudo = { [K in CSS.Pseudos]?: CSSProperties }
type CSSPropertiesComplete = SingleOrArray<CSS.Properties, keyof CSS.Properties>
[%%debugger.chrome];
/* This is the basic component. */
let component = ReasonReact.statelessComponent("Page");
type attr = ..;
type attr +=
| Str (string);
// import { ERROR_API_MIDDLEWARE } from '../constants/actions';
import { IAppState } from '../stateTypes';
import { Middleware, Dispatch } from 'redux';
/**
* Middleware that wraps `redux-pack` so that we may provide an API client factory
*/
type Client = any;
type CreateClient = (
dispatch: Dispatch<IAppState>,
import React, { Component } from 'react';
import { Text, View } from 'react-native';
import axios from 'axios';
import Product from '../../models/Product'
// Note the special import here!
interface ICardCollectionProps {
}
// FORKED by dan to improve typings for handler actions
declare module 'redux-pack' {
// Type definitions for redux-pack 0.1
// Project: https://github.com/lelandrichardson/redux-pack
// Definitions by: tansongyang <https://github.com/tansongyang>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
import { Action as ReduxAction, Middleware, Reducer } from 'redux';
{
"result": null,
"errors": [
{
"status": "4xx",
"code": "INVALID_FIELD_ERROR",
"source": "some.field[3].thing",
"message": "Must not be New York",
"detail": "Long description..."
},
import React from 'react';
import { KitAudioEntry } from '../../state/contentTypes';
import { Div } from 'glamorous';
type AudioProps = {
data: KitAudioEntry;
};
type State = {
iframeCode: string | null | undefined;
import * as React from 'react';
import { Div } from 'glamorous';
import { BigPlaceholder } from '../parts/BigPlaceholder';
type PersonDetailProps = { id: string };
export class PersonDetail extends React.Component<PersonDetailProps> {
render() {
return (
<LeftRightColPadding>