
Research
Security News
The Landscape of Malicious Open Source Packages: 2025 Mid‑Year Threat Report
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
@putout/plugin-types
Advanced tools
🐊Putout plugin adds ability to transform code related to types assertions
🐊Putout plugin adds ability to help with transforming code related to types.
npm i putout @putout/plugin-types -D
{
"rules": {
"types/declare": "on",
"types/convert-typeof-to-istype": "on",
"types/remove-useless-conversion": "on",
"types/remove-useless-constructor": "on",
"types/remove-double-negations": "on",
"types/remove-useless-typeof": "on",
"types/apply-is-array": "on"
}
}
Based on @putout/operator-declare
.
Supported assertions:
isString
;isEmptyString
;isNumber
;isNumberLike
- checks if a
can be convert to Number
from String
;isFn
;isBool
;isObject
;isUndefined
;isSymbol
;isNull
;isBigInt
;isArray
;isEmptyArray
;isError
;isString('hello');
isNumber('a' - 5);
const isString = (a) => typeof a === 'string';
const isNumber = (a) => !Number.isNaN(a) && typeof a === 'number';
isString('hello');
isNumber('a' - 5);
When you want to skip some declaration use dismiss
:
{
"rules": {
"types/declare": ["on", {
"dismiss": ["isString"]
}]
}
}
The
typeof
operator returns a string indicating the type of the unevaluated operand.(c) MDN
if (typeof a === 'boolean')
return x;
const isBool = (a) => typeof a === 'boolean';
if (isBool(a))
return x;
const a = !![1].includes(1);
const b = Boolean([1].includes(1));
const a = [1].includes(1);
Wrapper classes have surprising behaviour, such as
new Boolean(false)
evaluating totrue
.
🐊Putout plugin adds ability to remove useless constructor
. Use with new/remove-useless
.
const s = String('hello');
const b = Boolean(false);
const n = Number(5);
const s = 'hello';
const b = false;
const n = 5;
It is possible to use a couple of NOT operators (
!!
) in series to explicitly force the conversion of any value to the corresponding boolean primitive. The conversion is based on the "truthyness" or "falsyness" of the value.The same conversion can be done through the
Boolean
function.(c) MDN
if (!!a)
console.log('hi');
if (a)
console.log('hi');
The
typeof
operator returns a string indicating the type of the unevaluated operand.(c) MDN
typeof typeof 'hello';
typeof 'hello';
The
Array.isArray()
method determines whether the passed value is anArray
. When checking forArray
instance,Array.isArray()
is preferred overinstanceof
because it works throughiframes
.
x instanceof Array;
const {isArray} = Array;
isArray(x);
In case of using inline
option:
{
"rules": {
"types/apply-is-array": ["on", {
"inline": true
}]
}
}
Array.isArray
will be inlined:
Array.isArray(x);
MIT
Linter | Rule | Fix |
---|---|---|
🐊 Putout | types | ✅ |
⏣ ESLint | no-implicit-coercion | ✅ |
MIT
FAQs
🐊Putout plugin adds ability to transform code related to types assertions
The npm package @putout/plugin-types receives a total of 5,253 weekly downloads. As such, @putout/plugin-types popularity was classified as popular.
We found that @putout/plugin-types demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.