-
Notifications
You must be signed in to change notification settings - Fork 0
Generation Schema by Example
Justin Bush edited this page May 21, 2024
·
1 revision
const delay: number = 1000;
const message: string = "Hello, world!";
const isVisible: boolean = true;
function greet(name: string): void {
console.log(`Hello, ${name}!`);
}
function multiply(a: number, b: number): number {
return a * b;
}↓
enum TypeSwift {
case delay
case message
case isVisible
case greet(_ name: String)
case multiply(_ a: Double, _ b: Double)
}
const numbers: number[] = [1, 2, 3, 4, 5];
const names: string[] = ["Alice", "Bob", "Charlie"];
function sum(...values: number[]): number {
return values.reduce((acc, val) => acc + val, 0);
}
function sayHello(name: string = "Guest"): void {
console.log(`Hello, ${name}!`);
}↓
enum TypeSwift {
case numbers
case names
case sum(_ values: [Double])
case sayHello(_ name: String = "Guest")
}
enum Direction {
North = "N",
South = "S",
East = "E",
West = "W"
}
const defaultDirection: Direction = Direction.North;
function move(direction: Direction): void {
console.log(`Moving ${direction}`);
}
function calculateArea(width: number, height: number): number {
return width * height;
}↓
enum TypeSwift {
enum Direction {
case North, South, East, West
}
case defaultDirection
case move(_ direction: Direction)
case calculateArea(_ width: Double, _ height: Double)
}
type Point = {
x: number;
y: number;
};
const startPoint: Point = { x: 0, y: 0 };
const endPoint: Point = { x: 10, y: 20 };
function translate(point: Point, dx: number, dy: number): Point {
return { x: point.x + dx, y: point.y + dy };
}
function printPoint(point: Point): void {
console.log(`Point(${point.x}, ${point.y})`);
}↓
enum TypeSwift {
struct Point {
var x: Double
var y: Double
}
case startPoint
case endPoint
case translate(_ point: Point, _ dx: Double, _ dy: Double)
case printPoint(_ point: Point)
}