html-validator icon indicating copy to clipboard operation
html-validator copied to clipboard

[Typings imporve] format option should be required

Open fider opened this issue 4 years ago • 0 comments
trafficstars

Hi, nice lib.

In my opinion OptionsForHtmlFileAsValidationTargetAndObjectAsResult and OptionsForExternalUrlAsValidationTargetAndObjectAsResult should mark format as required, even if it contains only single value, because typings are not fulfilled in below case:

// JSON options
const options:
      | htmlValidator.OptionsForHtmlFileAsValidationTargetAndObjectAsResult
      | htmlValidator.OptionsForExternalUrlAsValidationTargetAndObjectAsResult
  = {
    data: args.html,
    isFragment: true
  };

// JSON response
let result: htmlValidator.ParsedJsonAsValidationResults;

try{
  result = await htmlValidator(options);
  ...
result.messages.length

In above case I expect result to be JSON, instead string is returned until format: 'json' is provided explicitly. This causes runtime error but should be detected during compilation.

fider avatar Apr 14 '21 14:04 fider