anycop

This is a tool to visualize any inferences included in the project code.

Usage no npm install needed!

<script type="module">
  import anycop from 'https://cdn.skypack.dev/anycop';
</script>

README

anycop๐Ÿ‘ฎโ€โ™‚๏ธ

This is a tool to visualize "any" inferences included in the TypeScript project code. Any type comes even if you don't want to. No matter how careful you are, once some library has been delivered, it cannot be prevented. Also, you may get lost in the code when you were in a hurry temporarily.

Take advantage of this tool to keep type safe code from getting lost or compromised. Once the situation is visualized, you can understand the problem and share it with the team. It would be great if You had time to work on improving the type safety coverage.

Any is not ruffian. Without TypeScript this specification would have been impossible to apply static typing to the current JavaScript ecosystem. Build better relationships with "any" with this tool.

What will this do?๐Ÿ‘ฎโ€โ™€๏ธ

When executed in the current directory of a TypeScript project, "any" inferred parts will be reported. The file path and kind found are logged. Then, the totals to be inspected and the type safety coverage are reported.

VScode is great, and if you run it with the built-in command line tool, you can jump to the corresponding location by pressing the output file path.

$ npm i -D anycop
$ anycop
/~/anycop/src/checkers.ts:45:12 ๐Ÿ‘ฎโ€โ™‚๏ธ < VariableDeclaration
/~/anycop/src/log.ts:9:9 ๐Ÿ‘ฎโ€โ™‚๏ธ < VariableDeclaration
/~/anycop/src/log.ts:9:17 ๐Ÿ‘ฎโ€โ™‚๏ธ < AsExpression
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      โ”‚ CheckCount โ”‚ AnyCount โ”‚ TypeSafe Coverage  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ VariableDeclaration  โ”‚ 45         โ”‚ 2        โ”‚ 0.9555555555555556 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ ParameterDeclaration โ”‚ 42         โ”‚ 0        โ”‚ 1                  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ BindingElement       โ”‚ 8          โ”‚ 0        โ”‚ 1                  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ FunctionDeclReturn   โ”‚ 9          โ”‚ 0        โ”‚ 1                  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ ArrowFunctionReturn  โ”‚ 13         โ”‚ 0        โ”‚ 1                  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ AsExpression         โ”‚ 3          โ”‚ 1        โ”‚ 0.6666666666666667 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Total                โ”‚ 120        โ”‚ 3        โ”‚ 0.975              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

How far it be detected?๐Ÿšจ

With the power of the TypeScript CompilerAPI, it can detect "any" inferences that are not mentioned in the code.

VariableDeclaration

Detects "any" inferences as well as explicit any annotations on variables.

function greet(message: any) {
  return message
}
// inferred "any" at VariableDeclaration
const message = greet('hello')

ParameterDeclaration

It detects not only the explicit annotation of the argument but also the case where the type definition referred to is equivalent to "any".

// annotation of "any" at ParameterDeclaration (message)
function greet(message: any) {
  return message
}

BindingElement

Detects when a reference expanded by an object is inferred by "any".

type Props = { a: any, b: any }
// inferred "any" at BindingElement (a & b)
function greet({ a, b }: Props) {
  return { a, b }
}

FunctionDeclReturn

It detects return types that have become "any", as well as explicit return type "any" annotations.

// inferred "any" at FunctionDeclReturn
function greet() {
  const message: any = 'hello'
  return message
}

ArrowFunctionReturn

It detects return types that have become "any", as well as explicit return type "any" annotations.

// inferred "any" at ArrowFunctionReturn
const abc = (param: string) => {
  switch (param) {
    case 'a':
      return true
    case 'b':
      return false
    case 'c':
      return '' as any
  }
}

AsExpression

Detect assertions by "as" keywords.

function greet() {
  return 'hello' as any // at AsExpression
}

anycop.config.js

By setting anycop.config.js in the project root, unique settings can be made. errorThrethold is the error reporting threshold.

If the total of "TypeSafe Coverage" falls below this value, an error can be generated. Please use it for introduction to integration tools.

// anycop.config.js
module.exports = {
  targetDir: ".",
  errorThrethold: 0.2
}