[英]Naming conventions for overload parameters in typescript
I need to have a function which takes in parameter as string or array of string. 我需要有一个将参数作为字符串或字符串数组的函数。
delete(keyOrKeys : string | string[]){
if(Array.isArray(keyOrKeys){
// delete all keys in array
} else {
// delete single key.
}
}
So, I need to follow good naming conventions. 因此,我需要遵循良好的命名约定。 What name should I use in place of 'keyOrkeys'.
我应该使用什么名称代替“ keyOrkeys”。 Or is it just fine ?
还是很好?
If you create definition for this function with real overloads (not just one implementation), you can name argument for each overload independently, eg: 如果使用真正的重载(不仅仅是一个实现)为此函数创建定义,则可以为每个重载独立命名参数,例如:
delete(key : string): void; // or whatever you are returning
delete(keys : string[]): void;
// this is useful for calling inside another function with union parameter
delete(keyOrKeys : string | string[]): void;
delete(keyOrKeys : string | string[]){
if(Array.isArray(keyOrKeys){
// delete all keys in array
} else {
// delete single key.
}
}
First of all delete
is a reserve keyword in Js. 首先
delete
是Js中的保留关键字。 Use deleteKeys
maybe. 也许使用
deleteKeys
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.