|
| 1 | +// Explicit any type |
| 2 | +function explicitAny(a: any): any { |
| 3 | + return a; |
| 4 | +} |
| 5 | + |
| 6 | +// Redeclared variable |
| 7 | +let foo = 123; |
| 8 | +let foo = 456; |
| 9 | + |
| 10 | +// Duplicate parameters |
| 11 | +function duplicateParams(a: number, a: number) { |
| 12 | + return a; |
| 13 | +} |
| 14 | + |
| 15 | +// Constant reassignment |
| 16 | +const MY_CONST = 'value'; |
| 17 | +MY_CONST = 'newValue'; |
| 18 | + |
| 19 | +// Invalid assignment |
| 20 | +function invalidAssignment() { |
| 21 | + true = false; |
| 22 | +} |
| 23 | + |
| 24 | +// Reserved keywords as identifiers |
| 25 | +const class = 'illegal'; |
| 26 | + |
| 27 | +// Unreachable code |
| 28 | +function unreachable(): number { |
| 29 | + return 1; |
| 30 | + console.log("never reached"); |
| 31 | +} |
| 32 | + |
| 33 | +// Misuse of async/await |
| 34 | +await Promise.resolve(); |
| 35 | + |
| 36 | +// Invalid usage of enum |
| 37 | +enum Colors { |
| 38 | + Red, |
| 39 | + Green, |
| 40 | + Red |
| 41 | +} |
| 42 | + |
| 43 | +// Empty interface |
| 44 | +interface EmptyInterface {} |
| 45 | + |
| 46 | +// Empty function body |
| 47 | +function emptyFunction() {} |
| 48 | + |
| 49 | +// Illegal use of break |
| 50 | +break; |
| 51 | + |
| 52 | +// Illegal use of continue |
| 53 | +continue; |
| 54 | + |
| 55 | +// Illegal return outside function |
| 56 | +return 123; |
| 57 | + |
| 58 | +// Unused variable |
| 59 | +let unusedVar: number = 5; |
| 60 | + |
| 61 | +// Use before definition |
| 62 | +console.log(undeclaredVar); |
| 63 | + |
| 64 | +// Duplicate object literal keys |
| 65 | +const myObject = { |
| 66 | + name: 'John', |
| 67 | + name: 'Doe' |
| 68 | +}; |
| 69 | + |
| 70 | +// Function overload conflict |
| 71 | +function overloadConflict(a: string): void; |
| 72 | +function overloadConflict(a: number): number; |
| 73 | +function overloadConflict(a: string | number) { |
| 74 | + return a; |
| 75 | +} |
| 76 | +function overloadConflict(a: boolean) { |
| 77 | + return a; |
| 78 | +} |
| 79 | + |
| 80 | +// Type assertion with no effect |
| 81 | +let someNum = 123 as number; |
| 82 | + |
| 83 | +// Useless cast |
| 84 | +let uselessCast = "hello" as any as string; |
| 85 | + |
| 86 | +// Shadowed variable |
| 87 | +let shadow = 1; |
| 88 | +function shadowVar() { |
| 89 | + let shadow = 2; |
| 90 | + return shadow; |
| 91 | +} |
| 92 | + |
| 93 | +// Illegal trailing commas |
| 94 | +const illegalTrailingComma = { |
| 95 | + foo: "bar", |
| 96 | +}; |
| 97 | + |
| 98 | +// Promise without await or catch |
| 99 | +async function promiseIssue() { |
| 100 | + Promise.resolve(); |
| 101 | +} |
| 102 | + |
| 103 | +// Misuse of generics |
| 104 | +function genericMisuse<T>(x: T) { |
| 105 | + return x.invalidProperty; |
| 106 | +} |