Eslint and this plugin conflict.
Eslint suggest that {string} should be {String}
This plugin suggests that {String} should be {string}
Jscs setting would be "checkTypes": "capitalizedNativeCase",
This has been discussed a number of times, e.g. https://github.com/gajus/eslint-plugin-jsdoc/issues/22.
ESLint is wrong to recommend String. 99% of the time you mean string, e.g.
// Thats 'string'
const foo = 'FOO';
// Thats 'String'
const bar = new String('BAR');
Right, so {String} is a valid type, regardless of if its not the common case.
Could there be an option to allow for these types? Like a nativeTypes vs strictNativeTypes
It is such a rare use case that I would like to avoid adding support for it, esp. since it has the potential of being abused to wrongly document native types.
I have not seen a single valid use of a native type constructor in the past 5 years. Prove me wrong and I will add this feature.
Ah I get it. {String} and {string} are technically both valid, but they are not the same.
new String('lard') === 'lard' // false
new String('lard') // String {0: "l", 1: "a", 2: "r", 3: "d", length: 4}
'lard' // "lard"
鈥婼o it's not about consistency, rather about probability of use.
type name | typeof | check-types | testcase
--|--|--|--
Object | object | Object | ({}) instanceof Object -> true
Array | object | Array | ([]) instanceof Array -> true
Date | object | Date | (new Date()) instanceof Date -> true
RegExp | object | RegExp | (new RegExp(/.+/)) instanceof RegExp -> true
Boolean | boolean | boolean | (true) instanceof Boolean -> false
Number | number | number | (41) instanceof Number -> false
String | string | string | ("test") instanceof String -> false
Confusing. But makes sense.
@Redsandro Please contribute a variation of this to the documentation. This is the most often asked question.
Most helpful comment
Ah I get it.
{String}and{string}are technically both valid, but they are not the same.鈥婼o it's not about consistency, rather about probability of use.
type name |
typeof| check-types | testcase--|--|--|--
Object | object | Object |
({}) instanceof Object->trueArray | object | Array |
([]) instanceof Array->trueDate | object | Date |
(new Date()) instanceof Date->trueRegExp | object | RegExp |
(new RegExp(/.+/)) instanceof RegExp->trueBoolean | boolean | boolean |
(true) instanceof Boolean->falseNumber | number | number |
(41) instanceof Number->falseString | string | string |
("test") instanceof String->falseConfusing. But makes sense.