linkifyjs icon indicating copy to clipboard operation
linkifyjs copied to clipboard

`linkify-element` 4.0.0-beta.3 missing type for `Options`

Open jryans opened this issue 3 years ago • 5 comments

When using linkify-element 4.0.0-beta.3, it seems the bundled type definitions in the package don't provide a type for the Options arg of linkifyElementHelper:

node_modules/linkify-element/index.d.ts:24:67 - error TS2304: Cannot find name 'Options'.

24 declare function linkifyElementHelper(element: HTMLElement, opts: Options, doc: Document): HTMLElement;

jryans avatar Jan 31 '22 12:01 jryans

One possible fix would be to use something like:

@param {import("linkifyjs").Options} opts

jryans avatar Jan 31 '22 12:01 jryans

I tried this locally, and this works for me:

diff --git a/packages/linkify-react/src/linkify-react.js b/packages/linkify-react/src/linkify-react.js
index 86af2ca..dba32cd 100644
--- a/packages/linkify-react/src/linkify-react.js
+++ b/packages/linkify-react/src/linkify-react.js
@@ -77,10 +77,14 @@ function linkifyReactElement(element, opts, elementId = 0) {
        return React.cloneElement(element, newProps, children);
 }

+/**
+ * @typedef { import("linkifyjs").Options } Options
+ */
+
 /**
  * @template P
  * @template {string | React.JSXElementConstructor<P>} T
- * @param {P & { as?: T, tagName?: T, tagName?: T, options?: any, children?: React.ReactNode}} props
+ * @param {P & { as?: T, tagName?: T, tagName?: T, options?: Options, children?: React.ReactNode}} props
  * @returns {React.ReactElement<P, T>}
  */
 const Linkify = (props) => {

Pike avatar Feb 01 '22 20:02 Pike

Well, "works" might be an overstatement, now that I try to actually use it. I think this might make tsc hang.

Pike avatar Feb 01 '22 21:02 Pike

Hi @jryans and @Pike, thank you both looking into this! I released v4.0.0-beta.4 some type improvements that should address this.

nfrasser avatar Feb 04 '22 15:02 nfrasser

Thanks for the quick fix! I can confirm the types are now working well for me with 4.0.0-beta.4.

jryans avatar Feb 04 '22 17:02 jryans