@tsonic/emitter 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +34 -0
- package/scripts/update-golden-tests.ts +119 -0
- package/src/adapter-generator.ts +112 -0
- package/src/array.test.ts +301 -0
- package/src/constants.ts +32 -0
- package/src/core/exports.ts +36 -0
- package/src/core/imports.test.ts +83 -0
- package/src/core/imports.ts +243 -0
- package/src/core/index.ts +9 -0
- package/src/core/module-emitter/assembly.ts +83 -0
- package/src/core/module-emitter/header.ts +19 -0
- package/src/core/module-emitter/index.ts +17 -0
- package/src/core/module-emitter/namespace.ts +39 -0
- package/src/core/module-emitter/orchestrator.ts +98 -0
- package/src/core/module-emitter/separation.ts +41 -0
- package/src/core/module-emitter/static-container.ts +75 -0
- package/src/core/module-emitter.test.ts +154 -0
- package/src/core/module-emitter.ts +6 -0
- package/src/core/module-map.ts +218 -0
- package/src/core/options.ts +16 -0
- package/src/core/type-params.ts +34 -0
- package/src/emitter-types/context.ts +91 -0
- package/src/emitter-types/core.ts +138 -0
- package/src/emitter-types/csharp-types.ts +42 -0
- package/src/emitter-types/formatting.ts +13 -0
- package/src/emitter-types/fqn.ts +81 -0
- package/src/emitter-types/index.ts +31 -0
- package/src/emitter.ts +107 -0
- package/src/expression-emitter.ts +112 -0
- package/src/expressions/access.ts +104 -0
- package/src/expressions/calls.ts +264 -0
- package/src/expressions/collections.ts +354 -0
- package/src/expressions/functions.ts +71 -0
- package/src/expressions/identifiers.ts +125 -0
- package/src/expressions/index.test.ts +515 -0
- package/src/expressions/index.ts +38 -0
- package/src/expressions/literals.ts +138 -0
- package/src/expressions/operators.ts +211 -0
- package/src/expressions/other.ts +63 -0
- package/src/generator-exchange.ts +120 -0
- package/src/generator.test.ts +193 -0
- package/src/golden-tests/config-parser.ts +67 -0
- package/src/golden-tests/discovery.ts +61 -0
- package/src/golden-tests/index.ts +10 -0
- package/src/golden-tests/registration.ts +26 -0
- package/src/golden-tests/runner.ts +131 -0
- package/src/golden-tests/tree-builder.ts +43 -0
- package/src/golden-tests/types.ts +21 -0
- package/src/golden.test.ts +40 -0
- package/src/hierarchical-bindings.test.ts +258 -0
- package/src/index.ts +14 -0
- package/src/integration.test.ts +303 -0
- package/src/specialization/call-site-rewriting.test.ts +99 -0
- package/src/specialization/collection/expressions.ts +184 -0
- package/src/specialization/collection/index.ts +7 -0
- package/src/specialization/collection/orchestrator.ts +25 -0
- package/src/specialization/collection/statements.ts +91 -0
- package/src/specialization/collection.ts +10 -0
- package/src/specialization/generation.ts +189 -0
- package/src/specialization/generic-classes.test.ts +59 -0
- package/src/specialization/generic-functions.test.ts +292 -0
- package/src/specialization/helpers.ts +39 -0
- package/src/specialization/index.ts +28 -0
- package/src/specialization/interfaces.test.ts +151 -0
- package/src/specialization/naming.ts +34 -0
- package/src/specialization/substitution.ts +186 -0
- package/src/specialization/type-aliases.test.ts +134 -0
- package/src/specialization/types.ts +19 -0
- package/src/specialization-generator.ts +23 -0
- package/src/statement-emitter.ts +117 -0
- package/src/statements/blocks.ts +115 -0
- package/src/statements/classes/helpers.ts +9 -0
- package/src/statements/classes/index.ts +13 -0
- package/src/statements/classes/inline-types.ts +79 -0
- package/src/statements/classes/members/constructors.ts +123 -0
- package/src/statements/classes/members/index.ts +8 -0
- package/src/statements/classes/members/methods.ts +137 -0
- package/src/statements/classes/members/orchestrator.ts +33 -0
- package/src/statements/classes/members/properties.ts +62 -0
- package/src/statements/classes/members.ts +6 -0
- package/src/statements/classes/parameters.ts +69 -0
- package/src/statements/classes/properties.ts +95 -0
- package/src/statements/classes.ts +14 -0
- package/src/statements/control/conditionals.ts +134 -0
- package/src/statements/control/exceptions.ts +59 -0
- package/src/statements/control/index.ts +11 -0
- package/src/statements/control/loops.ts +250 -0
- package/src/statements/control.ts +14 -0
- package/src/statements/declarations/classes.ts +89 -0
- package/src/statements/declarations/enums.ts +32 -0
- package/src/statements/declarations/functions.ts +147 -0
- package/src/statements/declarations/index.ts +10 -0
- package/src/statements/declarations/interfaces.ts +116 -0
- package/src/statements/declarations/structs.test.ts +182 -0
- package/src/statements/declarations/type-aliases.ts +104 -0
- package/src/statements/declarations/variables.ts +159 -0
- package/src/statements/declarations.ts +13 -0
- package/src/statements/index.test.ts +258 -0
- package/src/statements/index.ts +43 -0
- package/src/type-assertion.test.ts +143 -0
- package/src/type-emitter.ts +18 -0
- package/src/types/arrays.ts +21 -0
- package/src/types/dictionaries.ts +52 -0
- package/src/types/emitter.ts +76 -0
- package/src/types/functions.ts +45 -0
- package/src/types/index.test.ts +116 -0
- package/src/types/index.ts +14 -0
- package/src/types/intersections.ts +19 -0
- package/src/types/literals.ts +26 -0
- package/src/types/objects.ts +27 -0
- package/src/types/parameters.test.ts +146 -0
- package/src/types/parameters.ts +95 -0
- package/src/types/primitives.ts +24 -0
- package/src/types/references.ts +187 -0
- package/src/types/unions.test.ts +397 -0
- package/src/types/unions.ts +62 -0
- package/src/types.ts +33 -0
- package/testcases/README.md +213 -0
- package/testcases/arrays/basic/ArrayLiteral.ts +4 -0
- package/testcases/arrays/basic/config.yaml +1 -0
- package/testcases/arrays/destructuring/ArrayDestructure.ts +4 -0
- package/testcases/arrays/destructuring/config.yaml +1 -0
- package/testcases/arrays/methods/ArrayMethods.ts +6 -0
- package/testcases/arrays/methods/config.yaml +1 -0
- package/testcases/arrays/multidimensional/MultiDimensional.ts +10 -0
- package/testcases/arrays/multidimensional/config.yaml +1 -0
- package/testcases/arrays/spread/ArraySpread.ts +3 -0
- package/testcases/arrays/spread/config.yaml +1 -0
- package/testcases/async/basic/AsyncFunction.ts +5 -0
- package/testcases/async/basic/config.yaml +1 -0
- package/testcases/classes/abstract/AbstractClasses.ts +53 -0
- package/testcases/classes/abstract/config.yaml +1 -0
- package/testcases/classes/basic/Person.ts +12 -0
- package/testcases/classes/basic/config.yaml +1 -0
- package/testcases/classes/constructor/User.ts +11 -0
- package/testcases/classes/constructor/config.yaml +1 -0
- package/testcases/classes/field-inference/Counter.ts +11 -0
- package/testcases/classes/field-inference/config.yaml +1 -0
- package/testcases/classes/inheritance/Inheritance.ts +24 -0
- package/testcases/classes/inheritance/config.yaml +1 -0
- package/testcases/classes/static-members/MathHelper.ts +12 -0
- package/testcases/classes/static-members/config.yaml +1 -0
- package/testcases/control-flow/error-handling/ErrorHandling.ts +13 -0
- package/testcases/control-flow/error-handling/config.yaml +1 -0
- package/testcases/control-flow/loops/Loops.ts +21 -0
- package/testcases/control-flow/loops/config.yaml +1 -0
- package/testcases/control-flow/switch/SwitchStatement.ts +15 -0
- package/testcases/control-flow/switch/config.yaml +1 -0
- package/testcases/edge-cases/complex-expressions/ComplexExpressions.ts +10 -0
- package/testcases/edge-cases/complex-expressions/config.yaml +1 -0
- package/testcases/edge-cases/nested-scopes/NestedScopes.ts +10 -0
- package/testcases/edge-cases/nested-scopes/config.yaml +1 -0
- package/testcases/edge-cases/shadowing/Shadowing.ts +16 -0
- package/testcases/edge-cases/shadowing/config.yaml +1 -0
- package/testcases/functions/arrow/ArrowFunction.ts +5 -0
- package/testcases/functions/arrow/config.yaml +1 -0
- package/testcases/functions/basic/Greet.ts +3 -0
- package/testcases/functions/basic/config.yaml +1 -0
- package/testcases/functions/closures/Closures.ts +11 -0
- package/testcases/functions/closures/config.yaml +1 -0
- package/testcases/functions/default-params/DefaultParams.ts +7 -0
- package/testcases/functions/default-params/config.yaml +1 -0
- package/testcases/functions/rest-params/RestParams.ts +7 -0
- package/testcases/functions/rest-params/config.yaml +1 -0
- package/testcases/functions/type-guards/TypeGuards.ts +52 -0
- package/testcases/functions/type-guards/config.yaml +1 -0
- package/testcases/operators/logical/LogicalOperators.ts +11 -0
- package/testcases/operators/logical/config.yaml +1 -0
- package/testcases/operators/nullish-coalescing/NullishCoalescing.ts +7 -0
- package/testcases/operators/nullish-coalescing/config.yaml +1 -0
- package/testcases/operators/optional-chaining/OptionalChaining.ts +15 -0
- package/testcases/operators/optional-chaining/config.yaml +1 -0
- package/testcases/real-world/advanced-generics/advanced-generics.ts +116 -0
- package/testcases/real-world/advanced-generics/config.yaml +1 -0
- package/testcases/real-world/async-ops/async-ops.ts +67 -0
- package/testcases/real-world/async-ops/config.yaml +1 -0
- package/testcases/real-world/business-logic/business-logic.ts +215 -0
- package/testcases/real-world/business-logic/config.yaml +1 -0
- package/testcases/real-world/calculator/calculator.ts +29 -0
- package/testcases/real-world/calculator/config.yaml +1 -0
- package/testcases/real-world/data-structures/config.yaml +1 -0
- package/testcases/real-world/data-structures/data-structures.ts +133 -0
- package/testcases/real-world/functional/config.yaml +1 -0
- package/testcases/real-world/functional/functional.ts +116 -0
- package/testcases/real-world/shapes/config.yaml +1 -0
- package/testcases/real-world/shapes/shapes.ts +87 -0
- package/testcases/real-world/string-utils/config.yaml +1 -0
- package/testcases/real-world/string-utils/string-utils.ts +47 -0
- package/testcases/real-world/todo-list/config.yaml +1 -0
- package/testcases/real-world/todo-list/todo-list.ts +52 -0
- package/testcases/real-world/type-guards/config.yaml +1 -0
- package/testcases/real-world/type-guards/type-guards.ts +71 -0
- package/testcases/structs/basic/Point.ts +9 -0
- package/testcases/structs/basic/config.yaml +1 -0
- package/testcases/types/conditional/ConditionalTypes.ts +35 -0
- package/testcases/types/conditional/config.yaml +1 -0
- package/testcases/types/constants/ModuleConstants.ts +6 -0
- package/testcases/types/constants/config.yaml +1 -0
- package/testcases/types/generics/Generics.ts +15 -0
- package/testcases/types/generics/config.yaml +1 -0
- package/testcases/types/interfaces/Interfaces.ts +14 -0
- package/testcases/types/interfaces/config.yaml +1 -0
- package/testcases/types/mapped/MappedTypes.ts +27 -0
- package/testcases/types/mapped/config.yaml +1 -0
- package/testcases/types/tuples-intersections/TuplesAndIntersections.ts +46 -0
- package/testcases/types/tuples-intersections/config.yaml +1 -0
- package/testcases/types/unions/UnionTypes.ts +11 -0
- package/testcases/types/unions/config.yaml +1 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
- todo-list.ts: should emit real-world todo-list program
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface Todo {
|
|
2
|
+
id: number;
|
|
3
|
+
title: string;
|
|
4
|
+
completed: boolean;
|
|
5
|
+
createdAt: Date;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class TodoList {
|
|
9
|
+
private todos: Todo[] = [];
|
|
10
|
+
private nextId: number = 1;
|
|
11
|
+
|
|
12
|
+
addTodo(title: string): Todo {
|
|
13
|
+
const todo: Todo = {
|
|
14
|
+
id: this.nextId++,
|
|
15
|
+
title: title,
|
|
16
|
+
completed: false,
|
|
17
|
+
createdAt: new Date(),
|
|
18
|
+
};
|
|
19
|
+
this.todos.push(todo);
|
|
20
|
+
return todo;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
completeTodo(id: number): boolean {
|
|
24
|
+
const todo = this.todos.find((t) => t.id === id);
|
|
25
|
+
if (todo) {
|
|
26
|
+
todo.completed = true;
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getActiveTodos(): Todo[] {
|
|
33
|
+
return this.todos.filter((t) => !t.completed);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getCompletedTodos(): Todo[] {
|
|
37
|
+
return this.todos.filter((t) => t.completed);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getAllTodos(): Todo[] {
|
|
41
|
+
return [...this.todos];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function createSampleTodoList(): TodoList {
|
|
46
|
+
const list = new TodoList();
|
|
47
|
+
list.addTodo("Buy groceries");
|
|
48
|
+
list.addTodo("Write code");
|
|
49
|
+
list.addTodo("Exercise");
|
|
50
|
+
list.completeTodo(1);
|
|
51
|
+
return list;
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
- type-guards.ts: should emit real-world type-guards program
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export interface User {
|
|
2
|
+
type: "user";
|
|
3
|
+
id: number;
|
|
4
|
+
username: string;
|
|
5
|
+
email: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface Admin {
|
|
9
|
+
type: "admin";
|
|
10
|
+
id: number;
|
|
11
|
+
username: string;
|
|
12
|
+
email: string;
|
|
13
|
+
permissions: string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Guest {
|
|
17
|
+
type: "guest";
|
|
18
|
+
sessionId: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type Account = User | Admin | Guest;
|
|
22
|
+
|
|
23
|
+
export function isUser(account: Account): account is User {
|
|
24
|
+
return account.type === "user";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function isAdmin(account: Account): account is Admin {
|
|
28
|
+
return account.type === "admin";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function isGuest(account: Account): account is Guest {
|
|
32
|
+
return account.type === "guest";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getAccountDescription(account: Account): string {
|
|
36
|
+
if (isUser(account)) {
|
|
37
|
+
return `User: ${account.username} (${account.email})`;
|
|
38
|
+
} else if (isAdmin(account)) {
|
|
39
|
+
return `Admin: ${account.username} with ${account.permissions.length} permissions`;
|
|
40
|
+
} else if (isGuest(account)) {
|
|
41
|
+
return `Guest session: ${account.sessionId}`;
|
|
42
|
+
}
|
|
43
|
+
return "Unknown account type";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function hasEmail(account: Account): boolean {
|
|
47
|
+
return isUser(account) || isAdmin(account);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function getPermissions(account: Account): string[] {
|
|
51
|
+
if (isAdmin(account)) {
|
|
52
|
+
return account.permissions;
|
|
53
|
+
}
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Type guards with typeof
|
|
58
|
+
export function processValue(value: string | number | boolean): string {
|
|
59
|
+
if (typeof value === "string") {
|
|
60
|
+
return value.toUpperCase();
|
|
61
|
+
} else if (typeof value === "number") {
|
|
62
|
+
return value.toFixed(2);
|
|
63
|
+
} else {
|
|
64
|
+
return value ? "yes" : "no";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Array type guard
|
|
69
|
+
export function isStringArray(arr: unknown): arr is string[] {
|
|
70
|
+
return Array.isArray(arr) && arr.every((item) => typeof item === "string");
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
- Point.ts: should emit basic struct with properties
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type StringOrNumber = string | number | boolean;
|
|
2
|
+
|
|
3
|
+
// Using built-in conditional utility types
|
|
4
|
+
export type OnlyStrings = Extract<StringOrNumber, string>;
|
|
5
|
+
export type NoStrings = Exclude<StringOrNumber, string>;
|
|
6
|
+
export type NonNullableValue = NonNullable<string | null | undefined>;
|
|
7
|
+
|
|
8
|
+
// Custom conditional type
|
|
9
|
+
export type IsArray<T> = T extends any[] ? true : false;
|
|
10
|
+
|
|
11
|
+
export type ArrayCheck1 = IsArray<string[]>;
|
|
12
|
+
export type ArrayCheck2 = IsArray<string>;
|
|
13
|
+
|
|
14
|
+
// More complex conditional type
|
|
15
|
+
export type Unwrap<T> = T extends Promise<infer U> ? U : T;
|
|
16
|
+
|
|
17
|
+
export type UnwrappedString = Unwrap<Promise<string>>;
|
|
18
|
+
export type UnwrappedNumber = Unwrap<number>;
|
|
19
|
+
|
|
20
|
+
// Function using conditional type
|
|
21
|
+
export function processValue<T extends string | number>(
|
|
22
|
+
value: T
|
|
23
|
+
): T extends string ? number : string {
|
|
24
|
+
if (typeof value === "string") {
|
|
25
|
+
return value.length as any;
|
|
26
|
+
}
|
|
27
|
+
return value.toString() as any;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ReturnType utility
|
|
31
|
+
export function greet(name: string): string {
|
|
32
|
+
return `Hello ${name}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type GreetReturn = ReturnType<typeof greet>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
- ConditionalTypes.ts: should emit conditional types (Extract, Exclude, NonNullable)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
- ModuleConstants.ts: should emit module-level constants with explicit CLR types
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function identity<T>(value: T): T {
|
|
2
|
+
return value;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function firstElement<T>(arr: T[]): T | undefined {
|
|
6
|
+
return arr[0];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class Box<T> {
|
|
10
|
+
constructor(public value: T) {}
|
|
11
|
+
|
|
12
|
+
getValue(): T {
|
|
13
|
+
return this.value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
- Generics.ts: should emit generic functions and classes with type parameters
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface User {
|
|
2
|
+
name: string;
|
|
3
|
+
email: string;
|
|
4
|
+
age: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function greetUser(user: User): string {
|
|
8
|
+
return `Hello ${user.name}, age ${user.age}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface Point {
|
|
12
|
+
readonly x: number;
|
|
13
|
+
readonly y: number;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
- Interfaces.ts: should emit interfaces as C# classes with auto-properties
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface Person {
|
|
2
|
+
name: string;
|
|
3
|
+
age: number;
|
|
4
|
+
email: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// Using built-in utility types
|
|
8
|
+
export type PartialPerson = Partial<Person>;
|
|
9
|
+
export type RequiredPerson = Required<Person>;
|
|
10
|
+
export type ReadonlyPerson = Readonly<Person>;
|
|
11
|
+
|
|
12
|
+
// Custom mapped type
|
|
13
|
+
export type Nullable<T> = {
|
|
14
|
+
[P in keyof T]: T[P] | null;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type NullablePerson = Nullable<Person>;
|
|
18
|
+
|
|
19
|
+
// Function using mapped types
|
|
20
|
+
export function updatePerson(person: Person, updates: Partial<Person>): Person {
|
|
21
|
+
return { ...person, ...updates };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Function with readonly parameter
|
|
25
|
+
export function displayPerson(person: Readonly<Person>): string {
|
|
26
|
+
return `${person.name} (${person.age})`;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
- MappedTypes.ts: should emit mapped types (Partial, Required, Readonly)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Tuple types
|
|
2
|
+
export type Point2D = [number, number];
|
|
3
|
+
export type Point3D = [number, number, number];
|
|
4
|
+
export type NamedPoint = [x: number, y: number];
|
|
5
|
+
|
|
6
|
+
// Variadic tuples
|
|
7
|
+
export type Coords = [...number[]];
|
|
8
|
+
export type StringWithNumbers = [string, ...number[]];
|
|
9
|
+
|
|
10
|
+
// Intersection types
|
|
11
|
+
export interface Named {
|
|
12
|
+
name: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface Aged {
|
|
16
|
+
age: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type Person = Named & Aged;
|
|
20
|
+
|
|
21
|
+
// Complex intersection
|
|
22
|
+
export interface Serializable {
|
|
23
|
+
toJSON(): string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type SerializablePerson = Person & Serializable;
|
|
27
|
+
|
|
28
|
+
// Functions using tuples
|
|
29
|
+
export function distance(point: Point2D): number {
|
|
30
|
+
const [x, y] = point;
|
|
31
|
+
return Math.sqrt(x * x + y * y);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function createPoint(x: number, y: number): Point2D {
|
|
35
|
+
return [x, y];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Function using intersection
|
|
39
|
+
export function greetPerson(person: Person): string {
|
|
40
|
+
return `${person.name} is ${person.age} years old`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Rest elements with tuples
|
|
44
|
+
export function sum(...nums: [...number[]]): number {
|
|
45
|
+
return nums.reduce((a, b) => a + b, 0);
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
- TuplesAndIntersections.ts: should emit tuple types and intersection types
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function process(value: string | number): string {
|
|
2
|
+
if (typeof value === "string") {
|
|
3
|
+
return value.toUpperCase();
|
|
4
|
+
} else {
|
|
5
|
+
return value.toString();
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function maybeString(value: string | null): number {
|
|
10
|
+
return value?.length ?? 0;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
- UnionTypes.ts: should emit union types as Union<T1, T2> or nullable
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./dist",
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"composite": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"declarationMap": true,
|
|
9
|
+
"tsBuildInfoFile": "./dist/.tsbuildinfo"
|
|
10
|
+
},
|
|
11
|
+
"include": ["src/**/*.ts"],
|
|
12
|
+
"exclude": ["node_modules", "dist"],
|
|
13
|
+
"references": [{ "path": "../frontend" }]
|
|
14
|
+
}
|