Skip to content

Commit 4c5a78a

Browse files
committed
Merge branch '2025-typescript'
2 parents c391b91 + 4219d5a commit 4c5a78a

23 files changed

Lines changed: 1620 additions & 0 deletions

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
// Python settings
3+
// "python.envFile": "${workspaceFolder}/.env",,
4+
// Test settings
5+
"python.testing.pytestEnabled": true,
6+
// "python.testing.unittestEnabled": false,
7+
"python.testing.cwd": "${workspaceFolder}/tests",
8+
"python.defaultInterpreterPath": "${workspaceFolder}/2025/typescript/lokalise/.venv/bin/python"
9+
}

2025/typescript/addition.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function add(a: number, b: number): number {
2+
return a + b;
3+
}
4+
5+
console.log(add(5, 10)); // Compiles fine
6+
console.log(add("5", "10")); // Compilation error
7+
console.log(add("5", 10)); // Compilation error

2025/typescript/compiler_error.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function processData(data: string): string {
2+
return data.toLowerCase();
3+
}
4+
5+
console.log(processData("Hello")); // Works
6+
console.log(processData(123)); // Compilation error

2025/typescript/conversions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
console.log(true + true === 2) // => true
2+
console.log(true !== 1) // => true

2025/typescript/dynamic_typing.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let variable: any = 42; // variable is now of type number
2+
variable = 'hello world'; // variable is now of type string

2025/typescript/function.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from typing import Callable
2+
3+
type Greet = Callable[[str], str]
4+
5+
6+
def greet_fn(name: str) -> str:
7+
return f"Hello, {name}!"

2025/typescript/function.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
type Greet = (name: string) => string;
2+
const greetFn: Greet = (name) => `Hello, ${name}!`;

2025/typescript/greet.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def greet(name: str) -> str:
2+
return f"Hello, {name}!"
3+
4+
5+
print(greet("Arjan"))

2025/typescript/greet.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function greet(name: string): string {
2+
return `Hello, ${name}!`;
3+
}
4+
5+
console.log(greet("Arjan"));

2025/typescript/interface.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
interface Vehicle {
2+
speed: number;
3+
drive(): void;
4+
}
5+
6+
class Car implements Vehicle {
7+
constructor(public speed: number) {}
8+
9+
drive(): void {
10+
console.log(`Driving at ${this.speed} km/h`);
11+
}
12+
}
13+
14+
const myCar: Vehicle = new Car(120);
15+
myCar.drive(); // ✅ Works fine
16+
17+
const randomObject = { speed: 100, drive: () => console.log("Zoom!") };
18+
const anotherCar: Vehicle = randomObject; // ✅ Also works because it matches the interface

0 commit comments

Comments
 (0)