typescript.code-snippets 5.6 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
{
	"Constructor": {
		"prefix": "ctor",
		"body": [
			"/**",
			" *",
			" */",
			"constructor() {",
			"\tsuper();",
			"\t$0",
			"}"
		],
		"description": "Constructor"
	},
	"Class Definition": {
		"prefix": "class",
		"body": [
18 19
			"class ${1:name} {",
			"\tconstructor(${2:parameters}) {",
E
Erich Gamma 已提交
20 21 22 23 24 25 26 27 28 29
			"\t\t$0",
			"\t}",
			"}"
		],
		"description": "Class Definition"
	},
	"Public Method Definition": {
		"prefix": "public method",
		"body": [
			"/**",
30
			" * ${1:name}",
E
Erich Gamma 已提交
31
			" */",
32
			"public ${1:name}() {",
E
Erich Gamma 已提交
33 34 35 36 37 38 39 40
			"\t$0",
			"}"
		],
		"description": "Public Method Definition"
	},
	"Private Method Definition": {
		"prefix": "private method",
		"body": [
41
			"private ${1:name}() {",
E
Erich Gamma 已提交
42 43 44 45 46 47 48 49
			"\t$0",
			"}"
		],
		"description": "Private Method Definition"
	},
	"Import external module.": {
		"prefix": "import statement",
		"body": [
50
			"import { $0 } from \"${1:module}\";"
E
Erich Gamma 已提交
51 52 53 54 55 56 57
		],
		"description": "Import external module."
	},
	"Property getter": {
		"prefix": "get",
		"body": [
			"",
58
			"public get ${1:value}() : ${2:string} {",
59
			"\t${3:return $0}",
E
Erich Gamma 已提交
60 61 62 63 64 65 66 67
			"}",
			""
		],
		"description": "Property getter"
	},
	"Log to the console": {
		"prefix": "log",
		"body": [
68
			"console.log($1);",
E
Erich Gamma 已提交
69 70 71 72
			"$0"
		],
		"description": "Log to the console"
	},
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
	"Log warning to console": {
		"prefix": "warn",
		"body": [
			"console.warn($1);",
			"$0"
		],
		"description": "Log warning to the console"
	},
	"Log error to console": {
		"prefix": "error",
		"body": [
			"console.error($1);",
			"$0"
		],
		"description": "Log error to the console"
	},
E
Erich Gamma 已提交
89 90 91 92
	"Define a full property": {
		"prefix": "prop",
		"body": [
			"",
93 94
			"private _${1:value} : ${2:string};",
			"public get ${1:value}() : ${2:string} {",
95
			"\treturn this._${1:value};",
E
Erich Gamma 已提交
96
			"}",
97
			"public set ${1:value}(v : ${2:string}) {",
98
			"\tthis._${1:value} = v;",
E
Erich Gamma 已提交
99 100 101 102 103 104 105 106
			"}",
			""
		],
		"description": "Define a full property"
	},
	"Triple-slash reference": {
		"prefix": "ref",
		"body": [
107
			"/// <reference path=\"$1\" />",
E
Erich Gamma 已提交
108 109 110 111 112 113 114 115
			"$0"
		],
		"description": "Triple-slash reference"
	},
	"Property setter": {
		"prefix": "set",
		"body": [
			"",
116
			"public set ${1:value}(v : ${2:string}) {",
117
			"\tthis.$3 = v;",
E
Erich Gamma 已提交
118 119 120 121 122 123 124 125
			"}",
			""
		],
		"description": "Property setter"
	},
	"Throw Exception": {
		"prefix": "throw",
		"body": [
126
			"throw new Error(\"$1\");",
E
Erich Gamma 已提交
127 128 129 130 131 132 133
			"$0"
		],
		"description": "Throw Exception"
	},
	"For Loop": {
		"prefix": "for",
		"body": [
M
Matt Bierner 已提交
134
			"for (let ${1:index} = 0; ${1:index} < ${2:array}.length; ${1:index}++) {",
135
			"\tconst ${3:element} = ${2:array}[${1:index}];",
E
Erich Gamma 已提交
136 137 138 139 140 141 142 143
			"\t$0",
			"}"
		],
		"description": "For Loop"
	},
	"For-Each Loop using =>": {
		"prefix": "foreach =>",
		"body": [
144
			"${1:array}.forEach(${2:element} => {",
E
Erich Gamma 已提交
145 146 147 148 149 150 151 152
			"\t$0",
			"});"
		],
		"description": "For-Each Loop using =>"
	},
	"For-In Loop": {
		"prefix": "forin",
		"body": [
153
			"for (const ${1:key} in ${2:object}) {",
154
			"\tif (Object.prototype.hasOwnProperty.call(${2:object}, ${1:key})) {",
155
			"\t\tconst ${3:element} = ${2:object}[${1:key}];",
E
Erich Gamma 已提交
156 157 158 159 160 161
			"\t\t$0",
			"\t}",
			"}"
		],
		"description": "For-In Loop"
	},
M
Matt Bierner 已提交
162 163 164 165 166 167 168 169
	"For-Of Loop": {
		"prefix": "forof",
		"body": [
			"for (const ${1:iterator} of ${2:object}) {",
			"\t$0",
			"}"
		],
		"description": "For-Of Loop"
170 171 172 173
	},
	"For-Await-Of Loop": {
		"prefix": "forawaitof",
		"body": [
174 175 176 177
			"for await (const ${1:iterator} of ${2:object}) {",
			"\t$0",
			"}"
		],
178 179
		"description": "For-Await-Of Loop"
	},
E
Erich Gamma 已提交
180 181 182
	"Function Statement": {
		"prefix": "function",
		"body": [
183
			"function ${1:name}(${2:params}:${3:type}) {",
E
Erich Gamma 已提交
184 185 186 187 188 189 190 191
			"\t$0",
			"}"
		],
		"description": "Function Statement"
	},
	"If Statement": {
		"prefix": "if",
		"body": [
192
			"if (${1:condition}) {",
E
Erich Gamma 已提交
193 194 195 196 197 198 199 200
			"\t$0",
			"}"
		],
		"description": "If Statement"
	},
	"If-Else Statement": {
		"prefix": "ifelse",
		"body": [
201
			"if (${1:condition}) {",
E
Erich Gamma 已提交
202 203 204 205 206 207 208 209 210 211
			"\t$0",
			"} else {",
			"\t",
			"}"
		],
		"description": "If-Else Statement"
	},
	"New Statement": {
		"prefix": "new",
		"body": [
M
Matt Bierner 已提交
212
			"const ${1:name} = new ${2:type}(${3:arguments});$0"
E
Erich Gamma 已提交
213 214 215 216 217 218
		],
		"description": "New Statement"
	},
	"Switch Statement": {
		"prefix": "switch",
		"body": [
219 220
			"switch (${1:key}) {",
			"\tcase ${2:value}:",
E
Erich Gamma 已提交
221 222 223 224 225 226 227 228 229 230 231 232
			"\t\t$0",
			"\t\tbreak;",
			"",
			"\tdefault:",
			"\t\tbreak;",
			"}"
		],
		"description": "Switch Statement"
	},
	"While Statement": {
		"prefix": "while",
		"body": [
233
			"while (${1:condition}) {",
E
Erich Gamma 已提交
234 235 236 237 238 239 240 241 242 243
			"\t$0",
			"}"
		],
		"description": "While Statement"
	},
	"Do-While Statement": {
		"prefix": "dowhile",
		"body": [
			"do {",
			"\t$0",
244
			"} while (${1:condition});"
E
Erich Gamma 已提交
245 246 247
		],
		"description": "Do-While Statement"
	},
248
	"Try-Catch Statement": {
E
Erich Gamma 已提交
249 250 251 252
		"prefix": "trycatch",
		"body": [
			"try {",
			"\t$0",
253
			"} catch (${1:error}) {",
E
Erich Gamma 已提交
254 255 256 257 258 259 260 261
			"\t",
			"}"
		],
		"description": "Try-Catch Statement"
	},
	"Set Timeout Function": {
		"prefix": "settimeout",
		"body": [
M
Matt Bierner 已提交
262
			"setTimeout(() => {",
E
Erich Gamma 已提交
263
			"\t$0",
264
			"}, ${1:timeout});"
E
Erich Gamma 已提交
265 266
		],
		"description": "Set Timeout Function"
267 268 269 270 271 272 273 274 275 276 277 278 279 280
	},
	"Region Start": {
		"prefix": "#region",
		"body": [
			"//#region $0"
		],
		"description": "Folding Region Start"
	},
	"Region End": {
		"prefix": "#endregion",
		"body": [
			"//#endregion"
		],
		"description": "Folding Region End"
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
	},
	"new Promise": {
		"prefix": "newpromise",
		"body": [
			"new Promise<$1:type>((resolve, reject) => {",
			"\t$1",
			"})"
		],
		"description": "Create a new Promise"
	},
	"Async Function Statement": {
		"prefix": "async function",
		"body": [
			"async function ${1:name}(${2:params}:${3:type}) {",
			"\t$0",
			"}"
		],
		"description": "Async Function Statement"
	},
	"Async Function Expression": {
		"prefix": "async arrow function",
		"body": [
			"async (${1:params}:${2:type}) => {",
			"\t$0",
			"}"
		],
		"description": "Async Function Expression"
E
Erich Gamma 已提交
308
	}
309
}