Skip to content

Instantly share code, notes, and snippets.

@iffy
Created June 15, 2017 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iffy/9d518d78d6ead2fe1fbc9b0a4ba1a31d to your computer and use it in GitHub Desktop.
Save iffy/9d518d78d6ead2fe1fbc9b0a4ba1a31d to your computer and use it in GitHub Desktop.
Is "Account" a reserved name?
set -x
tsc okay.ts
tsc fails.ts
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;
};
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;
};
+ 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.
{
"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