Debian Codegraph @

tests/indent/typescript.ts

raw symbols SCIP
1 function classify(value: number): string {
2 switch (value) {
3 case 1:
4 return "one";
5 case 2:
6 console.log("two");
7 return "";
8 default:
9 return "other";
10 }
11 }
12
13 interface Shape {
14 readonly name: string;
15 area(): number;
16 }
17
18 type Handler = (event: string) => void;
19
20 enum Direction {
21 Up,
22 Down,
23 }
24
25 class Rectangle implements Shape {
26 constructor(
27 private width: number,
28 private height: number,
29 ) {}
30
31 get name(): string {
32 return "rectangle";
33 }
34
35 area(): number {
36 return this.width * this.height;
37 }
38 }
39
40 function process<T>(items: T[]): T[] {
41 const result: T[] = [];
42
43 const config = {
44 name: "test",
45 nested: {
46 value: 1,
47 },
48 };
49
50 for (const item of items) {
51 if (item) {
52 result.push(item);
53 }
54 }
55
56 try {
57 doSomething();
58 } catch (error) {
59 handle(error);
60 } finally {
61 cleanup();
62 }
63
64 return result;
65 }
66
67 const handler: Handler = (event) => {
68 console.log(event);
69 };
70
71 function totals(): number {
72 return [1, 2, 3]
73 .filter((n) => n > 0)
74 .map((n) => n * 2)
75 .reduce((a, b) => a + b, 0);
76 }
77
78 function template(): string {
79 const html = `
80 <div>
81 content
82 </div>
83 `;
84 return html;
85 }