-
-
Notifications
You must be signed in to change notification settings - Fork 114
Stop allowing extraSettings #60
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
Comments
I'm a bit conflicted here. On one hand, I agree, having I also agree that function remark2rehype(settings?: ToHastSettings)
function remark2rehype(destination?: Processor, settings?: ToHastSettings)
function remark2rehype(destinationOrSettings?: Processor | ToHastSettings, settings?: ToHastSettings) is a bit complex and might trip me up. On the other hand, One thing I've been researching is arbitrary length generic tuples (best resource so far https://stackoverflow.com/questions/49847407/typescript-generics-with-ordered-array-tuples) More research would be needed into the feasibility. Another item I've been researching, which would be simpler, would be using a rest on the /**
* An attacher is the thing passed to `use`.
* It configures the processor and in turn can receive options.
*
* Attachers can configure processors, such as by interacting with parsers and compilers, linking them to other processors, or by specifying how the syntax tree is handled.
*
* @this Processor context object is set to the invoked on processor.
* @param settings Configuration
* @param extraSettings Secondary configuration
* @typeParam S Plugin settings
* @typeParam P Processor settings
* @returns Optional Transformer.
*/
interface Attacher<S = Settings, P = Settings> {
(this: Processor<P>, ...settings: S[]): Transformer | void
}
/**
* A pairing of a plugin with its settings
*
* @typeParam S Plugin settings
* @typeParam P Processor settings
*/
type PluginTuple<S = Settings, P = Settings> = [Plugin<S, P>, ...S[]] Which is pretty simple, and would allow for an arbitrary number of settings.
let processor: Processor = unified()
interface ExamplePluginSettings {
example: string
}
const typedSetting = {example: 'example'}
const pluginWithTwoSettings: Plugin<Processor | ExamplePluginSettings> = (
processor?,
settings?
) => {}
// these should be valid (?), but are throwing type exceptions
// not sure why yet
processor.use(pluginWithTwoSettings, processor, typedSetting)
processor.use([pluginWithTwoSettings, processor, typedSetting])
processor.use([pluginWithTwoSettings, processor]) Removing Thoughts? 💭 |
A bit more research turned up microsoft/TypeScript#24897 and https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#tuples-in-rest-parameters-and-spread-expressions If I'm reading it correctly, it means something like type genericFunction<T extends any[]> = (...settings: T) => void
type genericTuple<T extends any[]> = [genericFunction<T>, ...T] should be possible, and typescript will automatically infer the types. Currently running this is blocked by a type exception: |
One thing to add: if this is a problem for types, well, that’s something to fix in plugins. They should use simpler APIs with less arguments. That does not mean unified itself should (or should not) allow multiple arguments. |
I've opened #62 as one possible solution that would remove |
I see. I'm glad to know what do you want. I guess I'm just a different person who prefers less usage options. Haha Anyway, I think this issue can be closed soon.(now or after merging #62) |
I think that makes sense! And I would agree, but there are also good reasons why things exist the way they are. Then again, it’s important that the API surface is reviewed often to see if things can change to be simpler. Most of the different ways of use are inspired by other similar projects (such as ware, postcss, rework, metalsmith), but also added over the years due to new features (the engine, presets). Some parts are legacy, and some parts are because unified can be used to do so many things (some of which never came into existence). |
Related to unifiedjs/unified#53. Related to unifiedjs/unified#54. Related to unifiedjs/unified#56. Related to unifiedjs/unified#57. Related to unifiedjs/unified#58. Related to unifiedjs/unified#59. Related to unifiedjs/unified#60. Related to unifiedjs/unified#61. Related to unifiedjs/unified#62. Related to unifiedjs/unified#63. Related to unifiedjs/unified#64. Related to #426. Reviewed-by: Titus Wormer <[email protected]> Reviewed-by: Junyoung Choi <[email protected]> Reviewed-by: Christian Murphy <[email protected]> Co-authored-by: Junyoung Choi <[email protected]> Co-authored-by: Christian Murphy <[email protected]>
@wooorm mentioned in #58 (comment)
I think allowing extraSettings is giving too much unnecessary freedom.
For example, remark-rehype is accepting two optional settings, a function for a destination processor and an object for ToHast settings. So remark-rehype should check the first argument's type if it is a function or an object. And we need to provide extra types like the below....
In my opinion, it might cause a little tiny bit of confusing for plugin providers and adopters. Haha
If we don't allow extra settings, remark-rehype could be coerced to become a bit simpler like the below example.
So, I'm down with this idea. But I also admit that this is a very trivial issue so we can just ignore.
The text was updated successfully, but these errors were encountered: