I have a project (say projectA) that contains some js
and some ts
files. The js
files were written ages ago, and there are many of them (1000s).
I want to create .d.ts
files for everything in this project so I can use them in projectB.
The process for that is fairly straightforward. I’ve been using Typescript to create the declaration files and then rollup to make it concise.
However, I’m noticing that it infers types for the .js
files, for eg,
const ArrowLeft = ({
height = _18,
width = _18,
fill = '#12a1dc',
title = 'Back',
...rest
}) => ()
gets inferred as
export default ArrowLeft;
declare function ArrowLeft({ height, width, fill, title, ...rest }: {
[x: string]: any;
height?: number;
width?: number;
fill?: string;
title?: string;
}): React.JSX.Element;
import React from "react";
Now, the height can actually be a string OR a number, so this inference then causes issues in projectB wherever I pass in string as height.
I want to either:
- Disable type inference altogether for JS files (just declare the module but not the type)
- Infer everything as
any
(soheight: any
)
And in an ideal world I would like to automate this instead of having to do work manually (for eg if there’s a tsconfig param/another tool)
I’ve tried:
- allowJS: false -> this gives me error when trying to rollup the ts files, because there is no declaration file for the JS files and I get ‘Cannot resolve module xxx’
- other ways of excluding JS, gave me similar errors
- lot of Googling, this was the closest thing to my problem: but the answers don’t work well for me. Ideally I just want inferred type to be
any
or there to be no type inference at all - this is also similar to my issue, but there wasn’t really a helpful answer (as I mentioned if I disallow JS then I run into a rollup issue)