tsdjs / tsd

Check TypeScript type definitions
MIT License
2.38k stars 68 forks source link

Add `--show-diff` cli option #165

Closed skarab42 closed 1 year ago

skarab42 commented 1 year ago

This PR add the --show-diff cli option.

image

Some limitations:

TODO:

skarab42 commented 1 year ago

Currently the feature is only implemented in expectType and needs to be implemented in the other helpers that support it. WIP... Done!

skarab42 commented 1 year ago

TODO:

  • Implement a normalized typeToString function.

I can't work on this feature any time soon... Anyway I was thinking of doing it in another PR. So I won't add anything more in this PR. Waiting for your feedback for eventual changes.

skarab42 commented 1 year ago

How were you thinking of doing a normalized typeToString function? I could try implementing it.

You have to explore the AST of the type if it is not stringifiable, you have to browse its properties and format them. It's a huge job with a lot of edge cases to take into account.

skarab42 commented 1 year ago

@tommy-mitchell I don't know why the CI doesn't pass... I don't see any difference in the output and all the tests run locally under Windows and WLS. Sorry but I can't investigate further.

tommy-mitchell commented 1 year ago

Seems like the CI is failing because the diff cli test reports the location of the errors, but doesn't locally:

+'dist/test/fixtures/diff/index.test-d.ts:8:0',
 '✖   8:0  Parameter type { life?: number | undefined; } is declared too wide for argument type { life: number; }.',
 '',
 '- { life?: number | undefined; }',
 '+ { life: number; }',
 // ...
tommy-mitchell commented 1 year ago

Looks good to me.