As of v6.0.0, @sindresorhus/is
now supports named exports, which should help with tree shaking.
This rule would auto-fix usages of is
, is.*
and assert.*
methods to only use named exports.
import is from '@sindresorhus/is';
const padLeft = (value: string, padding: string | number) => {
if (is.number(padding)) {
// `padding` is typed as `number`
return Array(padding + 1).join(' ') + value;
}
if (is.string(padding)) {
// `padding` is typed as `string`
return padding + value;
}
throw new TypeError(`Expected 'padding' to be of type 'string' or 'number', got '${is(padding)}'.`);
}
import {assert} from '@sindresorhus/is';
const handleMovieRatingApiResponse = (response: unknown) => {
assert.plainObject(response);
// `response` is now typed as a plain `object` with `unknown` properties.
assert.number(response.rating);
// `response.rating` is now typed as a `number`.
assert.string(response.title);
// `response.title` is now typed as a `string`.
return `${response.title} (${response.rating * 10})`;
};
import { detect, isNumber, isString } from '@sindresorhus/is';
const padLeft = (value: string, padding: string | number) => {
if (isNumber(padding)) {
// `padding` is typed as `number`
return Array(padding + 1).join(' ') + value;
}
if (isString(padding)) {
// `padding` is typed as `string`
return padding + value;
}
throw new TypeError(`Expected 'padding' to be of type 'string' or 'number', got '${detect(padding)}'.`);
}
import { assertNumber, assertPlainObject, assertString } from '@sindresorhus/is';
const handleMovieRatingApiResponse = (response: unknown) => {
assertPlainObject(response);
// `response` is now typed as a plain `object` with `unknown` properties.
assertNumber(response.rating);
// `response.rating` is now typed as a `number`.
assertString(response.title);
// `response.title` is now typed as a `string`.
return `${response.title} (${response.rating * 10})`;
};
No response
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too