Currently the interfaces for all options (e.g. RemarkParseOptions) require each setting to be defined.
As the options are populated by defaults (e.g. index.js ) not all settings are required to be defined.
Therefore the interfaces should look something like this:
interface RemarkParseOptions {
gfm?: boolean
commonmark?: boolean
footnotes?: boolean
blocks?: string[]
pedantic?: boolean
}
I am using remark in a typescript setting, and these non-optional settings interface requires me to either re-implement the default options or use a not strictly typed generic dict.
The settings on all option interfaces should be optional as they are not required to be set.
E.g. The following code segment should be a valid typescript code:
parserSettings: RemarkParseOptions = {};
As an alternative, it would be a possibility to export the default, so I can use the official defaults when implementing my options.
@Roang-zero1 the way to typing is structured precisely to guarantee that all settings are optional.
We do this through the use of Partial https://www.typescriptlang.org/docs/handbook/utility-types.html#partialt
https://github.com/remarkjs/remark/blob/de3de6d3321da594406fd628e9452a237d04aafc/packages/remark-parse/types/index.d.ts#L16-L17
It is intentional that the
interface RemarkParseOptions {
gfm?: boolean
commonmark?: boolean
footnotes?: boolean
blocks?: string[]
pedantic?: boolean
}
is not used, because it is easy to miss an optional annotation and break the typing.
It may be open to discussion if we want to export a version with Partial already applied.
Thoughts @Roang-zero1 @Rokt33r?
Oh nice feature, I did not know it worked that way.
Thanks for explaining.
Exporting the options with Partial applied would indeed work for my use-case.
_Edit: For reference this is the project where I want to use this interface_
For reference this is the project where I want to use this interface
Sounds interesting, the repository is private.
Made it public
@ChristianMurphy I'm agreeing with @Roang-zero1. I usually prefer to use ? rather than Partial because I sometimes found that several properties of an interface are not really optional in some case. For example, it should be difficult to present some condition like "if you set a option, then you have to set b option too" with Partial.
@Rokt33r if there is a strict dependency, I'd be okay with using ? for optionals with unions to reflect that more accurately.
I'm cautious using it otherwise, it has caused trouble on other projects, where settings were marked as required, when they were really optional.