eslint-plugin-vality
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

ESLint Plugin Vality

License Version Build Status Coverage Status

Snyk

See https://jeengbe.github.io/vality/eslint-plugin-vality for more information.

This page also assumes that you are somewhat familiar with Vality. If not, check that out first.

const Brand = {
  logo: v.dict([64, 128, 256], v.url),
};

type Brand = Parse<typeof Brand>;
/* {
  logo: {
    [x: number]: URL; // Where are the literal values???
  };
} */

Can you spot what's wrong with this model? Correct, it's missing the literal types for the keys. This is a common mistake when using Array or Enum Shorts and can be easily fixed by adding as const. (Find more information on this mistake here).

const Brand = {
  logo: v.dict([64, 128, 256] as const, v.url),
};

type Brand = Parse<typeof Brand>;
/* {
  logo: {
    64: URL;
    128: URL;
    256: URL;
  };
} */

Forgetting this sucks and can quickly become a source of frustration when suddenly types are weird. ESLint to the rescue! It will warn you when you forget to add as const in places where is may backfire and adds it automatically for you.

Now that you are interested, check out the full documentation for more information.

Package Sidebar

Install

npm i eslint-plugin-vality

Weekly Downloads

25

Version

2.0.3

License

MIT

Unpacked Size

27.2 kB

Total Files

19

Last publish

Collaborators

  • jeengbe