This file contains hidden or 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 isString(value?: any): value is string; |
This file contains hidden or 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 isPremiumUser(user: User): user is PremiumUser { | |
| return user.plan === 'premium' | |
| } | |
| function getPremiumOptions(user: User | PremiumUser): PremiumOptions | null { | |
| if (isPremiumUser(user)) { | |
| user | |
| // `user` is of type `PremiumUser` |
This file contains hidden or 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 isPremiumUser(user: User): user is PremiumUser { | |
| return user.plan === 'premium' | |
| } |
This file contains hidden or 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 UUID = string; | |
| interface User { | |
| id: UUID; | |
| first_name: string; | |
| last_name: string; | |
| plan: 'free' | 'premium' | |
| } | |
| interface PremiumOptions { |
This file contains hidden or 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) { |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |