Skip to content

Instantly share code, notes, and snippets.

View ctamyildirim's full-sized avatar

Cihan Tamyıldırım ctamyildirim

View GitHub Profile
class User {
constructor(name, email) {
this.name = name;
this.email = email;
}
}
let handler = {
deleteProperty(target, prop) {
if (prop === "email") {
class Book {
constructor(title, author, available) {
this.title = title;
this.author = author;
this.available = available;
}
}
let handler = {
has(target, prop) {
class User {
constructor(email) {
this.email = email;
}
}
let handler = {
construct(target, args) {
let email = args[0];
if (!isValidEmail(email)) {
let user = {
name: "John",
age: 30
};
let handler = {
get: function(target, prop, receiver) {
if (prop === "name") {
return target[prop];
} else if (prop === "age") {
throw new Error("Yaş özelliğine erişmek için izin verilmiyor!");
@ctamyildirim
ctamyildirim / union.ts
Last active March 11, 2024 22:35
Typescript Union Types
type Person = {
name: string;
age: number;
};
type Address = {
street: string;
city: string;
postalCode: number;
};
@ctamyildirim
ctamyildirim / enum.ts
Last active March 11, 2024 22:35
Typescript Enum
enum Direction {
Up = "UP",
Down = "DOWN",
Left = "LEFT",
Right = "RIGHT",
}
const up = Direction.Up;
@ctamyildirim
ctamyildirim / LiteralTypes.ts
Last active March 11, 2024 22:35
Typsecript Literal Types
// String literal type
const name: "John Doe" = "John Doe";
// Number literal type
const age: 30 = 30;
// Boolean literal type
const isLoggedIn: true = true;
// Enum literal type
@ctamyildirim
ctamyildirim / <>Operator.ts
Last active March 11, 2024 22:35
Typescript <>
const element = document.getElementById("my-element");
// element'in HTMLElement türünde olduğunu varsayıyoruz
const button = <HTMLButtonElement>element;
button.addEventListener("click", () => {
// ...
});
@ctamyildirim
ctamyildirim / as.ts
Last active March 11, 2024 22:34
Typescript as
const element = document.getElementById("my-element");
// element'in HTMLElement türünde olduğunu varsayıyoruz
const button = element as HTMLButtonElement;
button.addEventListener("click", () => {
// ...
});
@ctamyildirim
ctamyildirim / TypeDuplicate.ts
Last active March 11, 2024 22:34
Typescript Type failed
type Window = {
title: string;
}
type Window = {
ts: TypeScriptAPI;
}
// Error: Duplicate identifier 'Window'.