Skip to content
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

Regression: class implementing File errors with "missing property 'prototype'" #52166

Closed
pcattori opened this issue Jan 9, 2023 · 5 comments · Fixed by DefinitelyTyped/DefinitelyTyped#67034
Assignees
Labels
Bug A bug in TypeScript

Comments

@pcattori
Copy link

pcattori commented Jan 9, 2023

Bug Report

Original issue in the Remix repo: remix-run/remix#4371

Screen Shot 2023-01-09 at 11 28 39 AM

🔎 Search Terms

lib.dom.d.ts, File, Blob, interface, declare var, implements, prototype

🕗 Version & Regression Information

This changed between TS 4.8.4 and TS 4.9.3. Typechecking passed in 4.8.4, fails in 4.9.3+

⏯ Playground Link

Hard to reproduce in a playground because the issue only occurs when the class type definition is within node_modules/.

Playground shows no errors 🤷: https://www.typescriptlang.org/play?ssl=18&ssc=2&pln=1&pc=1#code/KYDwDg9gTgLgBAE2AYwDYEMrDm9BnPOAOQiQHkA7AEQEs8BrAMRtWxoFsxX3gKZDmrOAG8AUHAlwwUGgDd0MbADMWwMAoAWAbnGSYATzDAAXHDwwZFAOY7JUmfMVnUNZMCgB+W5Iroep80sbXQkMcwBZUhoVYARTCgBXdgAjd28JAHdgZPoaGAAlYAwYOWAABU0AixprdJwICkCE5BhoAAoVVnUYDSqggBo4AyM+mqtBvBc3T1MxOztzTBh4pNSoOrteOLhElLSQuABfOAAfOASKJBUKWIBKOqtgeDwaAC9gNtuVvfWDydcPotYB5vmtBlsQTtVu5BsNgJDAmMvnAAEKoCDJOqYKDofQohJKJTuT6mMpQCDsOjAAA8AEEoDi8QSiVAAHx1QLAPwkuCFdAIdDJVgAZQsXPY1PQFH07IOihAMB5ZIpVOpiOssrsj3gAG1hfoUhBUAA6VqioIAFXQVgAujz1cFDqIgA

💻 Code

To reproduce:

  1. npx create-remix@latest
  2. Pick Just the basics, Remix App Server, Typescript
  3. cd into project and run npm install if you skipped that in step (2)
  4. npm run typecheck

🙁 Actual behavior

❯ npm run typecheck

> typecheck
> tsc -b

node_modules/@remix-run/node/dist/upload/fileUploadHandler.d.ts:47:22 - error TS2420: Class 'NodeOnDiskFile' incorrectly implements interface 'File'.
  Property 'prototype' is missing in type 'NodeOnDiskFile' but required in type 'File'.

47 export declare class NodeOnDiskFile implements File {
                        ~~~~~~~~~~~~~~

  node_modules/typescript/lib/lib.dom.d.ts:2572:5
    2572     prototype: Blob;
             ~~~~~~~~~
    'prototype' is declared here.


Found 1 error.

The prototype: Blob code occurs within declare var Blob, not within interface Blob.
From my understanding, it seems like TS is conflating the Blob var and interface and that's what's causing this issue.

Screen Shot 2023-01-09 at 11 30 15 AM

🙂 Expected behavior

Typechecking succeeds

@MichaelDeBoey
Copy link

As @akomm pointed out in remix-run/remix#4371 (comment), we do get the error if we include types for any built-in Node modules: https://tsplay.dev/WYeObW

@MichaelDeBoey
Copy link

@iisaduan @RyanCavanaugh Is there anything we can do to help to get this one fixed?

I'm happy to help out in any way I can

@akomm
Copy link

akomm commented Jun 21, 2023

This problem would have been spotted earlier, if remix would actually type check out of the box when building. I don't get why its not, like for example in next. This is why nobody noticed this problem, as you only notice it if you fill the gap of missing typecheck and realize this failure. When you are in dev mode your IDE will only show you the problems in the currently working files. You actually have to manually run typescript. Another issue is that they use some internal version so the dependency of TS you install (and the remix create adds) is totally de-sync with the actually used. So I had an issue using 5.1 features having ts 5.1 when I realized remix does not use it at all. The communication here is bad and the behavior unexpected, even if it has reasons (esbuild or babel used, etc...).

@MichaelDeBoey
Copy link

@RyanCavanaugh Since 5.2 is now released, I guess this will not be fixed anytime soon?

If there's something we can help with to get this fixed, we're happy to help out!

@RyanCavanaugh
Copy link
Member

Something is wrong with the node .d.ts. It's basically saying, TL;DR

type __Blob = (the type of the global Blob value)
interface Blob extends __Blob { }

The implication here is that the instance type of Blob (interface Blob) has the static-side members of the value of the global Blob constructor. This isn't right. You can't write new new Blob(). The downstream impact of that is that when you say class X implements File, where File extends from Blob, that you're declaring that an instance of X is constructable; that you could say new new X() -- but no class works that way.

@iisaduan is investigating the right fix to the node .d.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants