Skip to content

Instantly share code, notes, and snippets.

View danvk's full-sized avatar

Dan Vanderkam danvk

View GitHub Profile
const INIT_VIEW: Pick<MapProps, 'center'|'zoom'|'pitch'|'bearing'|'style'> = {
center: [-73.991284, 40.741263],
zoom: [14.5],
pitch: [45],
bearing: [-17.6],
style: "mapbox://styles/mapbox/streets-v9"
};
const INIT_VIEW: Partial<Props> = {
center: [-73.991284, 40.741263],
zoom: [14.5],
pitch: [45],
bearing: [-17.6],
};
export function render(): JSX.Element {
return (
<Map
export interface Props {
 style: string | MapboxGl.Style;
 center?: [number, number];
 zoom?: [number];
 maxBounds?: MapboxGl.LngLatBounds | FitBounds;
 fitBounds?: FitBounds;
 fitBoundsOptions?: FitBoundsOptions;
 bearing?: [number];
 pitch?: [number];
 containerStyle?: React.CSSProperties;
import * as React from 'react';
import ReactMapboxGl from 'react-mapbox-gl';
const Map = ReactMapboxGl({
accessToken: '....',
});
export function render(): JSX.Element {
return (
<Map
interface Order {
 what: Product;
 how: 'bitcoin' | 'usd';
}
const order: Order = {
 what: 'Macbook Air',
 how: 'bitcoin'
};
purchase(order.what); // ok
const order = {
  what: 'Macbook Air' as Product, // or "as 'MacbookAir'"
  how: 'bitcoin'
};
purchase(order.what); // ok
const order = {
 what: 'Macbook Air',
 how: 'bitcoin'
};
order.what = 'Lenovo'; // valid
let newToy: Product = 'Macbook Air';
purchase(newToy); // ok
purchase('Macbook Air');
const newToy = 'Macbook Air';
purchase(newToy); // ok
type Product = 'iPad' | 'Mac Mini' | 'Macbook Air' | 'Macbook Pro';
export function purchase(what: Product) {
 // mine bitcoin…
 // send to apple…
}