Git Product home page Git Product logo

check-dts's Introduction

My projects and areas of expertise:

PostCSS logo      Browserslist logo      Autoprefixer logo      Logux logo      Size Limit logo      Size Limit logo      Storeon logo      SugarSS logo     

check-dts's People

Contributors

ai avatar antonk52 avatar bijela-gora avatar btakita avatar chenaski avatar dependabot[bot] avatar franciscop avatar michalcz avatar myshov avatar nawatts avatar palkan avatar shrpne avatar stnrepin avatar tyankatsu0105 avatar vasilii-kovalev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

check-dts's Issues

DataCloneError when using with TypeScript 4.5.0-dev.x

Summary

When using this library with Typescript 4.5.0-dev.x (right now, the latest available version is 4.5.0-dev.20211024), the following error occurs when trying to check the types:

DataCloneError: function (specifier, mode) {
return underlying.get(getUnderlyingCacheKey(specifier, mode));
} could not be cloned.

Steps to reproduce:

  1. Create a new folder
  2. Install typescript@next (or [email protected]) and check-dts (the latest version) there
  3. Create src folder
  4. Create a file index.ts inside the src folder and put the following content there:
    type Test = Record<string, boolean>;
    
    export type { Test };
  5. Create a file index.errors.ts inside the src/tests folder and put the following content there:
    import { Test } from "..";
    
    const test: Test = {
      // THROWS Type 'string' is not assignable to type 'boolean'.
      key: "value",
    };
  6. Run check-dts

Expected behavior

The types are checked successfully.

Actual behavior

The error occurs.

Stack trace:

DataCloneError: function (specifier, mode) {
  return underlying.get(getUnderlyingCacheKey(specifier, mode));
} could not be cloned.
at <path-to-the-project-directory>/node_modules/check-dts/worker.js:7:12
at ModuleJob.run (node:internal/modules/esm/module_job:175:25)
at async Loader.import (node:internal/modules/esm/loader:178:24)
at async Object.loadESM (node:internal/process/esm_loader:68:5)

Machine parameters

  • OS: Windows 10
  • Node version: 16.2.0

Additional information

  • The error doesn't occur for Typescript 4.4.4 (the latest stable one at the moment).
  • The error doesn't occur, if the Test type is defined right in the index.errors.ts file, i.e. it is used without import.
  • I understand, that the TypeScript's version I mentioned is not stable, but I'd like to know if there is a chance that the error remains when the stable version is released, i.e. is it possible to fix it on the check-dts library's side or not.

TypeError: Cannot read properties of undefined (reading 'text') when an error does not have the file prop

https://github.com/ai/check-dts/blob/main/check.js#L114

If the error does not have a file prop, the error occurs:

⠧ Check typesTypeError: Cannot read properties of undefined (reading 'text')
    at check (file:///home/brian/work/ctx-core/ctx-core/node_modules/.pnpm/[email protected]_oofdlok2qnlrhnlln2uverlm2m/node_modules/check-dts/check.js:114:48)
    at async run (file:///home/brian/work/ctx-core/ctx-core/node_modules/.pnpm/[email protected]_oofdlok2qnlrhnlln2uverlm2m/node_modules/check-dts/bin.js:24:18)

Error when project has JavaScript files

If a project has JavaScript files (jest.config.js, for example), they are used in the check as well as TypeScript ones, which leads to errors.
This pattern includes the JavaScript files:

globs = ['**/*.{js,ts,jsx,tsx}']

all variable contains the files because of the pattern:
let all = await globby(globs, opts)

Then, the library tries to get errors from the files:
let errors = await checkFiles(all, compilerOptions)

And inevitably fails at this point:
return i.file.fileName === j.fileName && line === j.line && !j.used

The error message is "TypeError: Cannot read property 'text' of undefined".

Any recommendation on checking the return value?

Do you have any recommendation on how to check that the return value type is correct? For example, let's say my method db.add() returns a string id inside a promise:

// How to ensure "id" is a string?
const id = await db.add(...);

// Current check, use a String-exclusive method:
id.startsWith('abc');

// (fails, as expected)
id.toFixed(2);

// Does not fail unfortunately
assert(typeof id === 'string');

What I'm doing right now is calling the type-specific method to check that it works, but is there a better/recommended way to do this? Thanks!

Node.js v15 compatibility?

Hey,

I'm getting an interesting error while checking the types using node.js v15 (runtime, not @types/node).

To run the check in node v14 you can do this:

git clone https://github.com/signicode/scramjet.git
cd scramjet
npm ci
cd .d.ts
npx check-dts

This works and checks all the data, but when I change the node version to 15 (for instance nvm i 15 && nvm use 15).

/workspace/scramjet/.d.ts [develop|✚ 1] 
11:17 $ npx check-dts index.d.ts
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /workspace/scramjet/.d.ts/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/workspace/scramjet/.d.ts/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

'extends' option does not supported

More info about extends: https://www.typescriptlang.org/tsconfig#extends

How to reproduce.

  1. check out to Evercoder/culori@f50f7e7#diff-b55cdbef4907b7045f32cc5360d48d262cca5f94062e353089f189f4460039e0R2
  2. run npm run check:dts
  3. command should fail with multiple errors
  4. inline "extends": "@tsconfig/node16-strictest/tsconfig.json", config like here Evercoder/culori@513e606#diff-b55cdbef4907b7045f32cc5360d48d262cca5f94062e353089f189f4460039e0
  5. run npm run check:dts
  6. command should finish successfully

Not working in NodeJS <12.16.0

I faced this error in CI pipeline on Node 12.5.0:

/app/node_modules/check-dts/bin.js:3
import { red } from 'colorette'
^^^^^^

SyntaxError: Cannot use import statement outside a module

Reproduce:

for node_version in {2..22}; do docker run --rm -it node:12.$node_version-alpine sh -c "node -v && npm -v && npx --node-arg=--experimental-modules check-dts"; done

In package.json specifies "node": ">=12.2.0", but NodeJS version in workflow resolves to the latest minor.

We can make a cjs version to support a wider range of NodeJS, or we can just increment the NodeJS version in package.json and specify the exact version in the workflow so the tests are "fair".

Support comments in tsconfig.json

Comments are allowed in tsconfig.json, but check-dts can't parse them and throw an error

I guess using json5 parser instead of JSON.parse should fix it

Different behavior for different end of line characters

The library throws "Wrong error" error for CRLF end of line (EOL) characters, but works fine for LF ones in the same test cases.

Steps to reproduce:

  1. Create test/index.errors.ts and write cases, that should throw an error. For example:

    // THROWS Type 'string' is not assignable to type 'number'.
    const variable: number = "variable";
  2. Make sure that file has CRLF EOL.

  3. Run check-dts.
    Actual behavior:

    ✖ src\tests\index.errors.ts:2:7: Wrong error
      Expected: Type 'string' is not assignable to type 'number'.
      Got: Type 'string' is not assignable to type 'number'.
    

    Expected behavior:

    ✔ src\tests\index.errors.ts
    
  4. Change CRLF EOL to LF one.

  5. Run check-dts.
    Actual behavior:

    ✔ src\tests\index.errors.ts
    

Duplicated if statements

There're duplicated if statements in the file check.js:

check-dts/check.js

Lines 144 to 167 in 463a1ea

if (failed) {
spinner.fail()
} else {
spinner.succeed()
}
if (!failed) {
for (let i of typeTests) {
print(chalk.green('✔ ') + formatName(cwd, i))
}
} else {
for (let file of all) {
if (bad[file]) {
print(r('✖ ') + formatName(cwd, file) + '\n')
}
let messages = (bad[file] || []).sort((msg1, msg2) => {
let line1 = parseInt(msg1.match(/(\d+):/)[1])
let line2 = parseInt(msg2.match(/(\d+):/)[1])
return line1 - line2
})
for (let i of messages) {
print(i + '\n')
}
}
}

Or:

if (failed) {
 // A
} else {
 // B
}
if (!failed) {
 // C
} else {
 // D
}

This construction looks strange because blocks A, D and B,C can be easily combined (and I think it will make the code more readable). Or are there some reasons for such a decision?

Checking IntelliSense?

The README mentions that positive tests can be used to check IntelliSense:

You can test IDE autocompletion in this file.

Is there a way to do so? It could be convenient to have something like:

// from index.d.ts
declare function foo<T>(bar: T): T;

// in index.types.ts

const baz = foo(1);

// EXPECTS type number
type test = typeof baz;

Just some way to have an expected (positive) value. Similarly, a way to check JSDoc comments on foo() would be nice. Not sure how feasible these are.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.