-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTypeScript.ts
More file actions
1308 lines (1018 loc) · 28.9 KB
/
TypeScript.ts
File metadata and controls
1308 lines (1018 loc) · 28.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// TYPESCRIPT - Typed JavaScript Superset - by Richard Rembert
// TypeScript is a strongly typed programming language that builds on JavaScript
// giving you better tooling at any scale. It compiles to plain JavaScript.
// SETUP AND BASICS
// Install TypeScript globally
// npm install -g typescript
// Install TypeScript for a project
// npm install --save-dev typescript
// npm install --save-dev @types/node // Node.js type definitions
// Create tsconfig.json
// npx tsc --init
// Compile TypeScript files
// tsc filename.ts // Compile single file
// tsc // Compile all files in project
// tsc --watch // Watch mode (recompile on changes)
// Run TypeScript directly (with ts-node)
// npm install -g ts-node
// ts-node filename.ts
// Basic tsconfig.json
/*
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"lib": ["ES2020", "DOM"],
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
*/
// BASIC TYPES
// Primitive types
let userName: string = "Alice";
let userAge: number = 25;
let isActive: boolean = true;
let undefinedValue: undefined = undefined;
let nullValue: null = null;
// Type inference (TypeScript can infer types)
let inferredString = "Hello"; // inferred as string
let inferredNumber = 42; // inferred as number
let inferredBoolean = true; // inferred as boolean
// Any type (avoid when possible)
let anything: any = "could be anything";
anything = 42;
anything = true;
// Unknown type (safer alternative to any)
let userInput: unknown;
userInput = "hello";
userInput = 42;
// Type checking with unknown
if (typeof userInput === "string") {
console.log(userInput.toUpperCase()); // OK, TypeScript knows it's a string
}
// Void type (functions that don't return a value)
function logMessage(message: string): void {
console.log(message);
}
// Never type (functions that never return)
function throwError(message: string): never {
throw new Error(message);
}
function infiniteLoop(): never {
while (true) {
// infinite loop
}
}
// ARRAYS AND TUPLES
// Array types
let numbers: number[] = [1, 2, 3, 4, 5];
let strings: Array<string> = ["hello", "world"];
let mixed: (string | number)[] = ["hello", 42, "world"];
// Array methods with typing
let fruits: string[] = ["apple", "banana"];
fruits.push("orange"); // OK
// fruits.push(42); // Error: number not assignable to string
// Readonly arrays
let readonlyNumbers: readonly number[] = [1, 2, 3];
// readonlyNumbers.push(4); // Error: push doesn't exist on readonly array
// Tuples (fixed length arrays with specific types)
let coordinate: [number, number] = [10, 20];
let nameAge: [string, number] = ["Alice", 25];
// Named tuples (TypeScript 4.0+)
let point: [x: number, y: number] = [10, 20];
// Optional tuple elements
let optionalTuple: [string, number?] = ["hello"];
// Rest elements in tuples
let restTuple: [string, ...number[]] = ["hello", 1, 2, 3];
// Tuple destructuring
let [x, y] = coordinate; // x: number, y: number
let [name, age] = nameAge; // name: string, age: number
// OBJECTS AND INTERFACES
// Object type annotations
let user: { name: string; age: number } = {
name: "Alice",
age: 25
};
// Optional properties
let optionalUser: { name: string; age?: number } = {
name: "Bob" // age is optional
};
// Readonly properties
let readonlyUser: { readonly id: number; name: string } = {
id: 1,
name: "Charlie"
};
// readonlyUser.id = 2; // Error: readonly property
// Index signatures
let scores: { [subject: string]: number } = {
math: 95,
science: 87,
english: 92
};
// Interfaces (preferred way to define object shapes)
interface Person {
name: string;
age: number;
email?: string; // optional property
readonly id: number; // readonly property
}
let person: Person = {
id: 1,
name: "Alice",
age: 25
};
// Interface inheritance
interface Employee extends Person {
department: string;
salary: number;
}
let employee: Employee = {
id: 1,
name: "Bob",
age: 30,
department: "Engineering",
salary: 75000
};
// Multiple interface inheritance
interface Timestamped {
createdAt: Date;
updatedAt: Date;
}
interface UserProfile extends Person, Timestamped {
bio: string;
}
// Interface methods
interface Calculator {
add(a: number, b: number): number;
subtract(a: number, b: number): number;
}
let calc: Calculator = {
add: (a, b) => a + b,
subtract: (a, b) => a - b
};
// Callable interfaces
interface StringProcessor {
(input: string): string;
}
let upperCase: StringProcessor = (input) => input.toUpperCase();
// UNION AND INTERSECTION TYPES
// Union types (OR)
let stringOrNumber: string | number;
stringOrNumber = "hello"; // OK
stringOrNumber = 42; // OK
// stringOrNumber = true; // Error
// Union with literal types
let size: "small" | "medium" | "large" = "medium";
// Type guards for unions
function processValue(value: string | number): string {
if (typeof value === "string") {
return value.toUpperCase(); // TypeScript knows it's a string
} else {
return value.toString(); // TypeScript knows it's a number
}
}
// Intersection types (AND)
interface Colorful {
color: string;
}
interface Circle {
radius: number;
}
type ColorfulCircle = Colorful & Circle;
let circle: ColorfulCircle = {
color: "red",
radius: 10
};
// LITERAL TYPES
// String literals
let direction: "north" | "south" | "east" | "west";
direction = "north"; // OK
// direction = "up"; // Error
// Numeric literals
let diceRoll: 1 | 2 | 3 | 4 | 5 | 6;
// Boolean literals
let truthyOnly: true = true;
// let falsyValue: true = false; // Error
// Template literal types (TypeScript 4.1+)
type Greeting = `hello ${string}`;
let greeting1: Greeting = "hello world"; // OK
let greeting2: Greeting = "hello there"; // OK
// let greeting3: Greeting = "hi there"; // Error
// ENUMS
// Numeric enums
enum Direction {
Up, // 0
Down, // 1
Left, // 2
Right // 3
}
let playerDirection: Direction = Direction.Up;
// Numeric enums with custom values
enum Status {
Pending = 1,
Approved = 2,
Rejected = 3
}
// String enums
enum Color {
Red = "red",
Green = "green",
Blue = "blue"
}
let favoriteColor: Color = Color.Red;
// Const enums (inlined at compile time)
const enum Planet {
Mercury = "mercury",
Venus = "venus",
Earth = "earth"
}
let homePlanet = Planet.Earth; // Compiles to: let homePlanet = "earth";
// Reverse mapping (numeric enums only)
console.log(Direction[0]); // "Up"
console.log(Direction["Up"]); // 0
// FUNCTIONS
// Function type annotations
function add(a: number, b: number): number {
return a + b;
}
// Arrow functions
const multiply = (a: number, b: number): number => a * b;
// Optional parameters
function greet(name: string, greeting?: string): string {
return greeting ? `${greeting}, ${name}!` : `Hello, ${name}!`;
}
// Default parameters
function createUser(name: string, age: number = 18): Person {
return { id: Date.now(), name, age };
}
// Rest parameters
function sum(...numbers: number[]): number {
return numbers.reduce((total, num) => total + num, 0);
}
// Function overloads
function combine(a: string, b: string): string;
function combine(a: number, b: number): number;
function combine(a: any, b: any): any {
return a + b;
}
let result1 = combine("Hello", " World"); // string
let result2 = combine(5, 10); // number
// Function types
type MathOperation = (a: number, b: number) => number;
let operation: MathOperation = (x, y) => x * y;
// Generic functions
function identity<T>(arg: T): T {
return arg;
}
let stringIdentity = identity<string>("hello");
let numberIdentity = identity<number>(42);
let inferredIdentity = identity("inferred"); // T inferred as string
// Generic constraints
interface Lengthwise {
length: number;
}
function logLength<T extends Lengthwise>(arg: T): T {
console.log(arg.length);
return arg;
}
logLength("hello"); // OK
logLength([1, 2, 3]); // OK
// logLength(42); // Error: number doesn't have length
// Multiple generic parameters
function swap<T, U>(a: T, b: U): [U, T] {
return [b, a];
}
let swapped = swap("hello", 42); // [number, string]
// CLASSES
// Basic class
class Animal {
name: string;
constructor(name: string) {
this.name = name;
}
speak(): void {
console.log(`${this.name} makes a sound`);
}
}
let dog = new Animal("Rex");
// Class inheritance
class Dog extends Animal {
breed: string;
constructor(name: string, breed: string) {
super(name);
this.breed = breed;
}
speak(): void {
console.log(`${this.name} barks`);
}
wagTail(): void {
console.log(`${this.name} wags tail`);
}
}
// Access modifiers
class BankAccount {
public accountNumber: string; // accessible everywhere
private balance: number; // only within this class
protected owner: string; // within this class and subclasses
constructor(accountNumber: string, owner: string) {
this.accountNumber = accountNumber;
this.owner = owner;
this.balance = 0;
}
public deposit(amount: number): void {
this.balance += amount;
}
public getBalance(): number {
return this.balance;
}
}
// Readonly modifier
class Circle {
readonly radius: number;
constructor(radius: number) {
this.radius = radius;
}
// this.radius = 10; // Error: readonly property
}
// Parameter properties (shorthand)
class User {
constructor(
public name: string,
private age: number,
readonly id: number
) {}
getAge(): number {
return this.age;
}
}
// Abstract classes
abstract class Shape {
abstract area(): number;
displayArea(): void {
console.log(`Area: ${this.area()}`);
}
}
class Rectangle extends Shape {
constructor(private width: number, private height: number) {
super();
}
area(): number {
return this.width * this.height;
}
}
// Static members
class MathUtils {
static PI = 3.14159;
static calculateCircleArea(radius: number): number {
return this.PI * radius * radius;
}
}
let area = MathUtils.calculateCircleArea(5);
// Getters and setters
class Temperature {
private _celsius: number = 0;
get celsius(): number {
return this._celsius;
}
set celsius(value: number) {
if (value < -273.15) {
throw new Error("Temperature below absolute zero");
}
this._celsius = value;
}
get fahrenheit(): number {
return (this._celsius * 9/5) + 32;
}
}
// Generic classes
class GenericContainer<T> {
private items: T[] = [];
add(item: T): void {
this.items.push(item);
}
get(index: number): T | undefined {
return this.items[index];
}
getAll(): T[] {
return [...this.items];
}
}
let stringContainer = new GenericContainer<string>();
stringContainer.add("hello");
let numberContainer = new GenericContainer<number>();
numberContainer.add(42);
/ GENERICS
// Generic interfaces
interface Repository<T> {
save(entity: T): void;
findById(id: string): T | undefined;
findAll(): T[];
}
// Generic type aliases
type ApiResponse<T> = {
data: T;
status: number;
message: string;
};
let userResponse: ApiResponse<User> = {
data: new User("Alice", 25, 1),
status: 200,
message: "Success"
};
// Generic constraints with keyof
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
let person = { name: "Alice", age: 25, email: "alice@example.com" };
let name = getProperty(person, "name"); // string
let age = getProperty(person, "age"); // number
// let invalid = getProperty(person, "height"); // Error: 'height' doesn't exist
// Conditional types
type NonNullable<T> = T extends null | undefined ? never : T;
type Example1 = NonNullable<string | null>; // string
type Example2 = NonNullable<number | undefined>; // number
// Mapped types
type Partial<T> = {
[P in keyof T]?: T[P];
};
type Required<T> = {
[P in keyof T]-?: T[P];
};
type Readonly<T> = {
readonly [P in keyof T]: T[P];
};
// Using utility types
interface User {
id: number;
name: string;
email: string;
}
type PartialUser = Partial<User>; // All properties optional
type RequiredUser = Required<User>; // All properties required
type ReadonlyUser = Readonly<User>; // All properties readonly
// Advanced mapped types
type Getters<T> = {
[K in keyof T as `get${Capitalize<string & K>}`]: () => T[K];
};
type UserGetters = Getters<User>;
// Results in:
// {
// getId: () => number;
// getName: () => string;
// getEmail: () => string;
// }
// TYPE ASSERTIONS AND TYPE GUARDS
// Type assertions (type casting)
let someValue: unknown = "hello world";
let strLength1 = (someValue as string).length;
let strLength2 = (<string>someValue).length; // JSX syntax conflicts
// Type guards
function isString(value: unknown): value is string {
return typeof value === "string";
}
function processValue(value: unknown): void {
if (isString(value)) {
console.log(value.toUpperCase()); // TypeScript knows it's a string
}
}
// instanceof type guard
class Bird {
fly(): void {
console.log("Flying...");
}
}
class Fish {
swim(): void {
console.log("Swimming...");
}
}
function move(animal: Bird | Fish): void {
if (animal instanceof Bird) {
animal.fly();
} else {
animal.swim();
}
}
// in operator type guard
interface Car {
drive(): void;
}
interface Boat {
sail(): void;
}
function operate(vehicle: Car | Boat): void {
if ("drive" in vehicle) {
vehicle.drive();
} else {
vehicle.sail();
}
}
// Discriminated unions
interface Square {
kind: "square";
size: number;
}
interface Rectangle {
kind: "rectangle";
width: number;
height: number;
}
interface Circle {
kind: "circle";
radius: number;
}
type Shape = Square | Rectangle | Circle;
function area(shape: Shape): number {
switch (shape.kind) {
case "square":
return shape.size * shape.size;
case "rectangle":
return shape.width * shape.height;
case "circle":
return Math.PI * shape.radius ** 2;
default:
const exhaustiveCheck: never = shape;
return exhaustiveCheck;
}
}
// MODULES AND NAMESPACES
// ES6 modules (preferred)
// math.ts
export function add(a: number, b: number): number {
return a + b;
}
export function subtract(a: number, b: number): number {
return a - b;
}
export default function multiply(a: number, b: number): number {
return a * b;
}
export { divide as div } from './calculator';
// main.ts
import multiply, { add, subtract } from './math';
import * as math from './math';
// Re-exports
export { User } from './user';
export * from './types';
// Namespaces (legacy, use modules instead)
namespace Utilities {
export function log(message: string): void {
console.log(`[LOG]: ${message}`);
}
export namespace StringUtils {
export function reverse(str: string): string {
return str.split('').reverse().join('');
}
}
}
Utilities.log("Hello");
Utilities.StringUtils.reverse("TypeScript");
// DECORATORS (Experimental)
// Enable in tsconfig.json: "experimentalDecorators": true
// Class decorator
function sealed(constructor: Function) {
Object.seal(constructor);
Object.seal(constructor.prototype);
}
@sealed
class BugReport {
type = "report";
title: string;
constructor(title: string) {
this.title = title;
}
}
// Method decorator
function enumerable(value: boolean) {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
descriptor.enumerable = value;
};
}
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
@enumerable(false)
greet() {
return "Hello, " + this.greeting;
}
}
// Property decorator
function format(formatString: string) {
return function (target: any, propertyKey: string): void {
let value = target[propertyKey];
const getter = () => `${formatString} ${value}`;
const setter = (newVal: string) => {
value = newVal;
};
Object.defineProperty(target, propertyKey, {
get: getter,
set: setter,
enumerable: true,
configurable: true,
});
};
}
class Person {
@format("Hello")
name: string;
constructor(name: string) {
this.name = name;
}
}
// UTILITY TYPES
// Built-in utility types
interface User {
id: number;
name: string;
email: string;
password: string;
}
// Partial - makes all properties optional
type PartialUser = Partial<User>;
// Required - makes all properties required
type RequiredUser = Required<PartialUser>;
// Readonly - makes all properties readonly
type ReadonlyUser = Readonly<User>;
// Pick - pick specific properties
type UserSummary = Pick<User, "id" | "name">;
// Omit - exclude specific properties
type CreateUser = Omit<User, "id">;
// Record - create object type with specific key and value types
type UserRoles = Record<string, "admin" | "user" | "guest">;
// Extract - extract types from union
type StringNumber = string | number | boolean;
type StringOrNumber = Extract<StringNumber, string | number>;
// Exclude - exclude types from union
type NonBoolean = Exclude<StringNumber, boolean>;
// NonNullable - exclude null and undefined
type NonNullString = NonNullable<string | null | undefined>;
// ReturnType - extract return type of function
function createUser(): User {
return { id: 1, name: "Alice", email: "alice@example.com", password: "secret" };
}
type CreateUserReturn = ReturnType<typeof createUser>; // User
// Parameters - extract parameter types of function
function updateUser(id: number, updates: Partial<User>): void {}
type UpdateUserParams = Parameters<typeof updateUser>; // [number, Partial<User>]
// ConstructorParameters - extract constructor parameter types
class Rectangle {
constructor(public width: number, public height: number) {}
}
type RectangleParams = ConstructorParameters<typeof Rectangle>; // [number, number]
// InstanceType - extract instance type of constructor
type RectangleInstance = InstanceType<typeof Rectangle>; // Rectangle
// ADVANCED TYPES
// Template literal types (TypeScript 4.1+)
type World = "world";
type Greeting = `hello ${World}`; // "hello world"
type EmailLocaleIDs = "welcome_email" | "email_heading";
type FooterLocaleIDs = "footer_title" | "footer_sendoff";
type AllLocaleIDs = `${EmailLocaleIDs | FooterLocaleIDs}_id`; // "welcome_email_id" | "email_heading_id" | "footer_title_id" | "footer_sendoff_id"
// Recursive types
type Json =
| string
| number
| boolean
| null
| { [property: string]: Json }
| Json[];
// Conditional types
type TypeName<T> =
T extends string ? "string" :
T extends number ? "number" :
T extends boolean ? "boolean" :
T extends undefined ? "undefined" :
T extends Function ? "function" :
"object";
type T1 = TypeName<string>; // "string"
type T2 = TypeName<number>; // "number"
type T3 = TypeName<() => void>; // "function"
// Distributive conditional types
type ToArray<T> = T extends any ? T[] : never;
type StrOrNumArray = ToArray<string | number>; // string[] | number[]
// infer keyword
type ReturnType<T> = T extends (...args: any[]) => infer R ? R : any;
type Unpromisify<T> = T extends Promise<infer U> ? U : T;
type T = Unpromisify<Promise<string>>; // string
// ERROR HANDLING
// Error types
class ValidationError extends Error {
constructor(public field: string, message: string) {
super(message);
this.name = "ValidationError";
}
}
// Result type pattern
type Result<T, E = Error> =
| { success: true; data: T }
| { success: false; error: E };
function parseNumber(input: string): Result<number> {
const num = parseInt(input, 10);
if (isNaN(num)) {
return { success: false, error: new Error("Invalid number") };
}
return { success: true, data: num };
}
// Using the result
const result = parseNumber("42");
if (result.success) {
console.log(result.data); // TypeScript knows this is number
} else {
console.error(result.error.message);
}
// Optional chaining and nullish coalescing
interface User {
name: string;
address?: {
street?: string;
city?: string;
};
}
const user: User = { name: "Alice" };
// Optional chaining
const street = user.address?.street;
const streetLength = user.address?.street?.length;
// Nullish coalescing
const displayName = user.name ?? "Anonymous";
const defaultStreet = user.address?.street ?? "Unknown Street";
// WORKING WITH EXTERNAL LIBRARIES
// Type definitions
// npm install --save-dev @types/lodash
// npm install --save-dev @types/node
// npm install --save-dev @types/react
// Ambient declarations
declare const API_KEY: string;
declare function gtag(command: string, ...args: any[]): void;
// Module declarations
declare module "custom-library" {
export function customFunction(): string;
export interface CustomInterface {
prop: number;
}
}
// Global augmentation
declare global {
interface Window {
customProperty: string;
}
namespace NodeJS {
interface ProcessEnv {
API_KEY: string;
DATABASE_URL: string;
}
}
}