You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Item 31: Don’t Repeat Type Information in Documentation
Things to Remember
Avoid repeating type information in comments and variable names. In the best case it is duplicative of type declarations, and in the worst case it will lead to conflicting information.
Declare parameters readonly rather than saying that you don't mutate them.
Consider including units in variable names if they aren't clear from the type (e.g., timeMs or temperatureC).
Code Samples
/** * Returns a string with the foreground color. * Takes zero or one arguments. With no arguments, returns the * standard foreground color. With one argument, returns the foreground color * for a particular page. */functiongetForegroundColor(page?: string){returnpage==='login' ? {r: 127,g: 127,b: 127} : {r: 0,g: 0,b: 0};}
/** Sort the strings by numeric value (i.e. "2" < "10"). Does not modify nums. */functionsortNumerically(nums: string[]): string[]{returnnums.sort((a,b)=>Number(a)-Number(b));}
/** Sort the strings by numeric value (i.e. "2" < "10"). */functionsortNumerically(nums: readonlystring[]): string[]{returnnums.sort((a,b)=>Number(a)-Number(b));// ~~~~ ~ ~ Property 'sort' does not exist on 'readonly string[]'.}
/** Sort the strings by numeric value (i.e. "2" < "10"). */functionsortNumerically(nums: readonlystring[]): string[]{returnnums.toSorted((a,b)=>Number(a)-Number(b));// ok}