-
Notifications
You must be signed in to change notification settings - Fork 17
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
TypeScript dom
lib FormData
and File
type compatibility
#57
Comments
Hey, good catch, I have never really tested types compatibility. I tried to fix this, but it introduces different errors (with ReadableStream), so I will continue attempt to improve compatibility later this day, because it's late night here, sorry. |
Tried in fresh setup with the code from latest commit and it does seem to work now, I don't get any errors. tsconfig.json: {
"include": ["test.mjs"],
"exclude": ["node_modules"],
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true,
"target": "esnext",
"baseUrl": ".",
"moduleResolution": "node"
}
} test.mjs import {FormData as FormDataNode} from "formdata-node"
/** @type {FormData} */
const form = new FormDataNode()
form.set("hello", "Hello, World!") Can you confirm? Just install my package right from github, it should be compiled right away. |
Not sure why the error mentioned in my first comment is happening, but I assume TS falls back to |
I tried using your As a side note, I recommend replacing |
Do you have tsconfig.json in your project? I don't see this error when I have one. |
I use a {
"compilerOptions": {
"maxNodeModuleJsDepth": 10,
"module": "nodenext",
"noEmit": true,
"strict": true
},
"typeAcquisition": {
"enable": false
}
} With this config you need to add a |
You don't if you set With |
While working on v6 I found out that types for global ReadableStream have no Then if I would use Weird. I'm not sure what to do, but I probably will choose to support types for global Maybe I'm missing something and there's already typings for I think this could probably be related: microsoft/TypeScript#29867 |
v6 is available now, check out release notes for more information: https://github.com/octet-stream/form-data/releases/tag/v6.0.0 |
imo i think typescript should remove this non speced webkitRelativePath... ppl should not depend on it... |
Great, I just found out that on the type-level my Blob implementation is not compatible to either Node.js' one, to node-fetch, and undici. And that's just because I have |
It would be great if the
FormData
class exported by this package was compatible with the TypeScriptdom
libFormData
type. The same goes (I guess) for theFile
class.This would allow libraries to specify
FormData
type from the TypeScriptdom
lib for function arguments, etc. and not cause type problems for projects that are usingFormData
instances from this package with that.It looks like the
File
class needs to have awebkitRelativePath
property to be complaint.MDN links to this spec for the property:
https://wicg.github.io/entries-api/#dom-file-webkitrelativepath
Given that the TypeScript
dom
lib types don't havewebkitRelativePath
as an optional type, it must mean it's implemented by all browsers?For context, I am preparing a big
apollo-upload-client
update that (among other things) adds type safety and am wondering how to type the functioncreateUploadLink
optionFormData
which allows users to customise theFormData
class used; the first thing I'm trying istypeof FormData
which references the TypeScriptdom
lib type, but then in tests it results in a type error when I try to useFormData
from this package with that option.The text was updated successfully, but these errors were encountered: