Issue
I have the following:
interface IUser {
email: string
password: string
}
class User {
email: string
password: string
constructor(email: string, password: string) {
this.email = email
this.password = password
}
isEmailValid(): boolean {
return validatorJs.isEmail(this.email)
}
isPasswordValid(): boolean {
return validatorJs.isStrongPassword(this.password, opts)
}
}
function createUser(user: IUser) {
// applying isPasswordValid and isEmailValid
//insert ...
}
function getUser(): IUser {
return new User('foo@bar.com', 'foobar')
}
I have to put the letter "I" before the interface name, is that correct or should I do it differently?
Solution
Someone has developed a TypeScript style guide. You can find it here: https://ts.dev/style
From that guide:
This is the style guide for the TypeScript language that was based on the one that is provided by Google. It contains both rules and best practices. Choose those that work best for your team.
This is what it says about interface naming:
Do not mark interfaces specially (
IMyInterfaceorMyFooInterface) unless it's idiomatic in its environment. When introducing an interface for a class, give it a name that expresses why the interface exists in the first place (e.g. class TodoItem and interface TodoItemStorage if the interface expresses the format used for storage/serialization in JSON).
Answered By - DeborahK
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.