-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
misc edits #13
misc edits #13
Conversation
Used: `typings-checker test.ts`. Error: `Cannot find module './checker'`. Not sure why `index.ts` did have a compiled version!
how come I still had this?
- without JSON.stringify it concats the array (fails on all lines for me since 1.1). - converting objects to strings, prettier but mostly prevents the objects from being printed one property per line.
I managed to do a replace to convert my assertions to inline format. Edit: just noticed the existing tests for both cases, and can't reproduce there. Odd. |
please don't lock me in to a specific version. :(
I bumped into this when the TS type def library isn't loaded properly.
I tried a version of your bash script for ramda too; using variants of that might be of interest to other users as well. |
Thanks for the changes! I'll review them shortly. re: inline assertions, they were intended to be in addition to full-line assertions, not a replacement for them. If you have a test file that 1.1 broke, please add it to this repo and let's fix the bug! |
Yeah, I noticed the tests afterwards. Take your time on the review, and feel free to ask. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes -- I left a bunch of comments / questions for you.
@@ -31,6 +31,11 @@ An `$ExpectType` directive tests the type of the expression on the next line. Th | |||
npm install -g typings-checker | |||
typings-checker your-test.ts | |||
|
|||
## options | |||
|
|||
* `--noLines` (`-l`): hide line numbers in output -- useful if you don't want these clogging diff logs when you add or remove a line. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain the use case for this a little more? I'd expect most users of typings-checker would just care about the exit code. As an analogy, the tsc
command doesn't have an option to suppress line numbers. Ideally we'd just have a single output format that's good for everyone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So line numbers are good info -- either way you'll wanna know what code just broke.
The thing here was, like TS and like you, I'm storing the output in git so as to be able to see the diffs.
The issue I wanted to solve here was, if that output log in git contains the line numbers, once you add/remove a line near the start (or whatever), all the line numbers would change, and your diff log would be clogged with a lot of noise (one line per type check), which could crowd out the useful info.
The alternative, showing code snippets, could also change of course, though at least not as easily in all places at once. That's why I added those two options.
Perhaps alternatively it might work to separate things such that info printed to the user and info printed to the diff log would differ here, maybe using stdout
vs. stderr
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My inclination would be to just leave both of these options out. If you want to filter out line numbers, you can do it with a bash one-liner:
typings-checker test.ts | perl -pe 's/\.ts:(\d+)/.ts/'
But I still don't totally understand the use case. Wouldn't you always want zero assertion failures, just like you wouldn't want to commit code that doesn't compile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filtering out the line numbers that way seems like an interesting alternative to me. It hadn't occurred to me, though I suppose I'd felt the option might help people in a similar situation -- which I hope wouldn't be many. Including the code fragments was just a way to make it useful even without line numbers.
Zero assertion failures sounds wonderful to me. I do want that, but that's not where we are for ramda right now; there are quite some blocking issues preventing me from reaching that point even if I wanted to: erased generics, lack of support for heterogeneous map()
, lack of type-level support for reduce()
, quite possibly support for higher-kinded types, not to mention whatever other features this list might depend on, aside from just finding the time to figure out every single step between here and proper type inference.
I mean, TypeScript has 1,800+ outstanding issues at the moment, so in that sense, I fear it's no surprise to find that not everything is quite perfect yet. FP libraries are probably among the harder ones to type, but I'm probably also being more ambitious than e.g. the lodash typings -- if I map over an object, I'd like for my IDE to know both the (distinct) types and keys of each value. Settling for vague types is an easy way to pass all tests (as you noted), but in a sense feels to me like it beats the point of doing a typings library.
To me this was also the reason to commit and diff the output, like you were. Up to now I had no idea if an edit would break inference and turned everything into any
. With your library, now I do. But I need to be able to answer bigger questions than that; notably: given my current assertion failures (whether any
or errors), would switching to an experimental branch make that overall situation better or worse?
I also hope I can get to the point of having the luxury to get things fixed. And I'm about to find out more about that -- knowing what's good or bad now, I can finally start seeing more about that.
@@ -4,6 +4,7 @@ | |||
"description": "Positive and negative assertions about TypeScript types and errors", | |||
"main": "src/index.js", | |||
"scripts": { | |||
"prepublish": "tsc ./src/index.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tsc
alone should be sufficient here -- the tsconfig.json
will tell it what to compile.
"yargs": "^6.6.0" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "2.x" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the effect of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Peer dependency: see above.
Yargs: I used this to parse command-line options (not order-dependent like the earlier process.argv
method).
"chai": "^3.5.0", | ||
"mocha": "^3.2.0", | ||
"ts-node": "^2.0.0" | ||
"ts-node": "^2.0.0", | ||
"typescript": "^2.1.4" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We import symbols from typescript, so it doesn't make sense for it to be a devDependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intention: ensuring users would not be locked in to a specific TS version (peer dependency). Evidently it would still be needed at run-time though. This was my idea of addressing that.
I'm open to ideas, just hope we wouldn't need to force every single DefinitelyTyped repo to force adhering one and the same TypeScript version.
For Ramda, for one, I'm highly dependent on fixes to the outstanding problems in TypeScript. I'd actually consider trying out different branches / forks for that.
numSuccesses: number; | ||
failures: Failure[]; | ||
} | ||
import { Assertion, TypeAssertion, ErrorAssertion, Failure, WrongTypeFailure, UnexpectedErrorFailure, WrongErrorFailure, MissingErrorFailure, NodedAssertion, Report } from './types'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split this to one symbol per line or use import * as types from './types';
@@ -1,4 +1,4 @@ | |||
tests/basics/type-assertion-failure.ts:6: Expected type | |||
tests/basics/type-assertion-failure.ts:6:: Expected type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ::
double colon doesn't look right (here and elsewhere)
@@ -5,6 +5,7 @@ set +o errexit | |||
|
|||
for test in $(find tests -name '*.ts'); do | |||
node src/index.js $test > $test.out 2>&1 | |||
rc=${PIPESTATUS[0]}; if [[ $rc != 0 ]]; then exit $rc; fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's going on here? If there are errors, the checker should fail. But sometimes that's expected. So it shouldn't be a test failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presently it'd continue to run the git commands even if the test could not be completed. This addresses that, just existing with error code if it failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But for some of the tests (e.g. tests/underscore-any.ts
), failure is expected. Does this script error out when you run it locally?
@@ -10,18 +10,37 @@ | |||
*/ | |||
|
|||
import * as ts from 'typescript'; | |||
let argv = require('yargs') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
@@ -10,18 +10,37 @@ | |||
*/ | |||
|
|||
import * as ts from 'typescript'; | |||
let argv = require('yargs') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use import
instead of require
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started with import
, but it seems they use this syntax for getting in those extra configuration methods before the actual method extraction. At that point I chose to just follow their way, but open to suggestions.
const host = ts.createCompilerHost(options, true); | ||
// read options from a tsconfig.json file. | ||
let host = ts.createCompilerHost({}, true); | ||
const options: ts.CompilerOptions = ts.readConfigFile('tsconfig.json', (path: string) => host.readFile(path)).config['compilerOptions']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that the tests now run with typings-checker's own tsconfig.json
? That's probably fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the consuming project's tsconfig. To me that was the point here, making it configurable to match how a project would want to get compiled.
I've incorporated your feedback for the points where it was clear how.
|
Let's get rid of the command-line flags, so that the main thrust of this PR is factoring out the types and loading the tsconfig file. Changing the bash script to reference And a test for the no-file error would be great. I'd like to add tslint to this project but I'll hold off until this is in, since there will presumably be many merge conflicts. |
To clarify, would you prefer the code snippets out as well? |
did those now (currently keeping code); I'll go sleep now, so feel free to edit yourself. |
Closing in favor of #19. I dropped the inclusion of code snippets in error messages for now. I also added a |
Feel free to use/ignore, these seemed useful to me. On that last point... yeah, since 1.1 it's failing to attach for me (using old separate-line assertions) on every single line.