Skip to content

Instantly share code, notes, and snippets.

@david-arteaga
Created January 11, 2020 21:34
Show Gist options
  • Save david-arteaga/19c77cf2828e5da36b8274498b1964da to your computer and use it in GitHub Desktop.
Save david-arteaga/19c77cf2828e5da36b8274498b1964da to your computer and use it in GitHub Desktop.
[Typescript VS Code snippets]
{
// Place your snippets for typescript here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Redux Request, Success, Failure Constants": {
"prefix": "rxreqconst",
"body": [
"export const $1_REQUEST = '$1_REQUEST';",
"export const $1_SUCCESS = '$1_SUCCESS';",
"export const $1_FAIL = '$1_FAIL';"
],
"description": "Redux constants for request, success, fail actions"
},
"Express async function handler": {
"prefix": "eha",
"body": [
"async $1(req: express.Request, res: express.Response) {",
" $2",
"}"
]
},
"Injectable Service": {
"prefix": "iservice",
"body": [
"import { Injectable } from '../di/di';",
"",
"@Injectable()",
"export class $1 {",
" constructor() {}",
"",
" $2",
"}",
""
]
},
"Bookshelf Class Model": {
"prefix": "bkmodel",
"body": [
"import { bookshelf } from '../bookshelf';",
"",
"export class $2 extends bookshelf.Model<$2> {",
" get tableName() {",
" return '$1';",
" }",
" get idAttribute() {",
" return '$3';",
" }",
"}",
"",
"export namespace $2 {",
" export const tableName = '$1';",
" export enum Related {",
" }",
" export type Type = DB.$1 & {};",
"}",
""
]
},
"Graphql resolver": {
"prefix": "gqlresolver",
"body": [
"import { gql } from 'apollo-server';",
"import { GraphqlResolver, GraphqlDefaultExport } from '../../util/GraphqlTypes';",
"",
"const schema = gql`$1`;",
"",
"const resolver = () =>",
" <GraphqlResolver>{",
" Mutation: {},",
" Query: {}",
" };",
"",
"export default <GraphqlDefaultExport>{",
" schema: [schema],",
" resolvers: [resolver()]",
"};",
""
]
},
"Service graphql method": {
"prefix": "gqlservmethod",
"body": [
"public async $1(",
" input: GQL.I${1/(^.)(.*)/${1:/upcase}$2/}Input,$2",
"): Promise<GQL.I${1/(^.)(.*)/${1:/upcase}$2/}Payload> {",
" $3",
"}"
]
},
"Async arrow function": {
"prefix": "aaf",
"body": "async ($1) => {$2}"
},
"Async it": {
"prefix": "ait",
"body": ["it('$1', async () => {", " $2", "})"]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment