Xoá file
This commit is contained in:
56
error.ts
56
error.ts
@@ -1,56 +0,0 @@
|
||||
// Basic TypeScript file with review issues
|
||||
|
||||
function add(a: number, b: number): number {
|
||||
return a + b // Missing semicolon, no type safety for return
|
||||
}
|
||||
|
||||
const result = add('1', 2); // Passing string instead of number
|
||||
console.log(result)
|
||||
|
||||
// 1. Unused variable
|
||||
let unusedVar: string;
|
||||
|
||||
// 2. Function with wrong return type
|
||||
function getString(): number {
|
||||
return "hello" // Should return number
|
||||
}
|
||||
|
||||
// 3. Variable declared but never used
|
||||
let neverUsed = 123;
|
||||
|
||||
// 4. Type assertion error
|
||||
let x: any = "abc";
|
||||
let y: number = x as number; // Wrong assertion
|
||||
|
||||
// 5. Shadowed variable
|
||||
let a = 5;
|
||||
function shadow() {
|
||||
let a = "shadowed";
|
||||
return a;
|
||||
}
|
||||
|
||||
// 6. Function missing return type
|
||||
function noReturnType() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 7. Incorrect interface usage
|
||||
interface User {
|
||||
name: string;
|
||||
age: number;
|
||||
}
|
||||
const user: User = { name: "A", age: "20" }; // age should be number
|
||||
|
||||
// 8. Array with mixed types
|
||||
const arr: number[] = [1, "2", 3];
|
||||
|
||||
// 9. Unreachable code
|
||||
function unreachable() {
|
||||
return 1;
|
||||
console.log("This will never run");
|
||||
}
|
||||
|
||||
// 10. Using 'any' type unnecessarily
|
||||
function useAny(a: any, b: any): any {
|
||||
return a + b;
|
||||
}
|
||||
Reference in New Issue
Block a user