Skip to content

Instantly share code, notes, and snippets.

@Aldhanekaa
Created March 5, 2021 06:04
Show Gist options
  • Select an option

  • Save Aldhanekaa/e08f9b3ce8836d7a2241fe5a3f9e07ca to your computer and use it in GitHub Desktop.

Select an option

Save Aldhanekaa/e08f9b3ce8836d7a2241fe5a3f9e07ca to your computer and use it in GitHub Desktop.
// Welcome to the TypeScript Playground, this is a website
// which gives you a chance to write, share and learn TypeScript.
// You could think of it in three ways:
//
// - A place to learn TypeScript in a place where nothing can break
// - A place to experiment with TypeScript syntax, and share the URLs with others
// - A sandbox to experiment with different compiler features of TypeScript
const anExampleVariable = "Hello World"
console.log(anExampleVariable)
// To learn more about the language, click above in "Examples" or "What's New".
// Otherwise, get started by removing these comments and the world is your playground.
function wrapInArray(obj: string | string[]): string | string[] {
if (typeof obj === "string") {
return obj;
// ^ = (parameter) obj: string
} else {
return [...obj];
}
}
console.log(wrapInArray(["asd", "asd"]))
interface virtualPoint {
x?: number;
y?: number;
}
class VirtualPoint {
x: number;
y: number;
constructor(x: number, y: number) {
this.x = x;
this.y = y;
}
}
const newVPoint:virtualPoint = new VirtualPoint(13, 56);
console.log(newVPoint.x)
interface Props {
a?: number;
b?: string;
}
const NamaKu = {name:"Aldhan"}
enum Color {
Red = 1,
Green = 2,
Blue = 4,
}
let c: Color = Color.Green;
type A = {
name: String;
}
class Food<T> implements A {
constructor(public readonly name: String, private b?: String) {
}
}
abstract class Person<T> {
private name: T;
constructor(name: T) {
this.name = name;
}
protected getName() {
return this.name;
}
abstract bruh(): void;
}
class PersonChild<T> extends Person<T> {
constructor(name: T) {
super(name)
}
bruh(): void{
console.log(this.getName()) // equeals to super.getName()
}
}
let x = new PersonChild<String>("Aldhan");
let b = new Food<String>("Sushi");
console.log(x.bruh())
let a = new PersonChild<String>("s");
interface Greeting<A, B> {
(name: A): B;
}
const myGreeting: Greeting<String, String> = (name: String) => `${name} Hello!`;
console.log(myGreeting("Aldhan"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment