Created
June 15, 2017 16:19
-
-
Save iffy/9d518d78d6ead2fe1fbc9b0a4ba1a31d to your computer and use it in GitHub Desktop.
Is "Account" a reserved name?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -x | |
tsc okay.ts | |
tsc fails.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface IObject { | |
id: number; | |
table_name: string; | |
}; | |
interface IUser extends IObject { | |
name: string; | |
}; | |
class User implements IUser { | |
id: number; | |
table_name: string = 'user'; | |
name: string; | |
}; | |
interface IAccount extends IObject { | |
user_id: number; | |
name: string; | |
}; | |
class Account implements IAccount { | |
id: number; | |
table_name: string = 'account'; | |
user_id: number; | |
name: string; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface IObject { | |
id: number; | |
table_name: string; | |
}; | |
interface IUser extends IObject { | |
name: string; | |
}; | |
class User implements IUser { | |
id: number; | |
table_name: string = 'user'; | |
name: string; | |
}; | |
interface IAccount extends IObject { | |
user_id: number; | |
name: string; | |
}; | |
class Hello implements IAccount { | |
id: number; | |
table_name: string = 'account'; | |
user_id: number; | |
name: string; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ tsc okay.ts | |
+ tsc fails.ts | |
fails.ts(19,7): error TS2420: Class 'Account' incorrectly implements interface 'IAccount'. | |
Property 'name' is optional in type 'Account' but required in type 'IAccount'. | |
fails.ts(20,3): error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'string', but here has type 'number'. | |
fails.ts(20,3): error TS2687: All declarations of 'id' must have identical modifiers. | |
fails.ts(23,3): error TS2687: All declarations of 'name' must have identical modifiers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"@types/node": "^7.0.31", | |
"typescript": "^2.3.4" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment