Skip to content

Conversation

@remcohaszing
Copy link
Contributor

@remcohaszing remcohaszing commented Mar 11, 2024

This bases the MDX type tests on real world examples. Different frameworks use different type definitions for the JSX namespace. This is what I envision the tests could look like.

Please fill in this template.

If changing an existing definition:

cc @jakebailey

This bases the MDX type tests on real world examples. Different
frameworks use different type definitions for the JSX namespace.
@jakebailey
Copy link
Member

ts-eslint's support for project references is not so good; you'd need to set this up just like I did #68908 and put tsconfigs without references at the root.

@remcohaszing remcohaszing force-pushed the mdx-test-real-frameworks branch from 153524a to c7666ca Compare March 11, 2024 16:36
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
Comment on lines 16 to 21
namespace JSX {
type Element = runtime.JSX.Element;
type ElementClass = runtime.JSX.ElementClass;
type ElementType = runtime.JSX.ElementType;
type IntrinsicElements = runtime.JSX.IntrinsicElements;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a bit sad to find out this is necessary. I initially thought this would work, but it doesn’t:

declare module 'mdx/types' {
  import { JSX } from 'preact/jsx-runtime'
}

@jakebailey
Copy link
Member

I think to fix the current errors, you should go back to types: [] and instead use reference directives to load react/preact.

@jakebailey
Copy link
Member

Seems like the test only fails due to the JSX namespace needing to be declared?

@remcohaszing remcohaszing changed the title Base MDX type tests on real worls examples Base MDX type tests on real world examples Mar 12, 2024
@remcohaszing
Copy link
Contributor Author

The JSX namespace is declared in types/mdx/preact-tests.tsx via module augmentation. I don’t see why it’s currently not working. I’m pretty sure this worked before.

@jakebailey
Copy link
Member

The one declared in the preact file is on the preact module, but index.d.ts is looking for the one in the globals.

@jakebailey
Copy link
Member

Seems like it's passing; are you wanting this to get merged in? (It's currently a draft but seems good to me.)

@remcohaszing
Copy link
Contributor Author

I think it’s good, but seeing Preact integration depends on declaration merging, I would like to add some docs for this. Also now that this works, I want to test Vue and Solid integration.

I’m marking it Ready for review to ping other maintainers, see if they also think this is a good idea.

@remcohaszing remcohaszing marked this pull request as ready for review March 14, 2024 16:23
@typescript-bot
Copy link
Contributor

typescript-bot commented Mar 14, 2024

@remcohaszing Thank you for submitting this PR!

This is a live comment which I will keep updated.

1 package in this PR

Code Reviews

Because this is a widely-used package, a DT maintainer will need to review it before it can be merged.

You can test the changes of this PR in the Playground.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ✅ A DT maintainer needs to approve changes which affect module config files

All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 68955,
  "author": "remcohaszing",
  "headCommitOid": "d51924efb0e19162a72cc5cd33c738dae1ae6d8e",
  "mergeBaseOid": "55df51f723ed778b0960e1fe3ae43a3590a88d58",
  "lastPushDate": "2024-03-11T10:53:13.000Z",
  "lastActivityDate": "2024-03-22T10:52:38.000Z",
  "mergeOfferDate": "2024-03-22T00:06:29.000Z",
  "mergeRequestDate": "2024-03-22T10:52:38.000Z",
  "mergeRequestUser": "remcohaszing",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "mdx",
      "kind": "edit",
      "files": [
        {
          "path": "types/mdx/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/mdx/package.json",
          "kind": "package-meta-ok"
        },
        {
          "path": "types/mdx/preact-tests.tsx",
          "kind": "test"
        },
        {
          "path": "types/mdx/react-tests.tsx",
          "kind": "test"
        },
        {
          "path": "types/mdx/tsconfig.json",
          "kind": "package-meta-ok"
        },
        {
          "path": "types/mdx/tsconfig.preact.json",
          "kind": "package-meta",
          "suspect": "not [the expected form](https://github.com/DefinitelyTyped/DefinitelyTyped#user-content-tsconfigjson) (check: `compilerOptions.jsxFactory`)"
        },
        {
          "path": "types/mdx/tsconfig.react.json",
          "kind": "package-meta-ok"
        },
        {
          "path": "types/mdx/types.d.ts",
          "kind": "definition"
        }
      ],
      "owners": [
        "ChristianMurphy",
        "remcohaszing",
        "wooorm"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "jakebailey",
      "date": "2024-03-22T00:05:46.000Z",
      "isMaintainer": true
    },
    {
      "type": "approved",
      "reviewer": "ChristianMurphy",
      "date": "2024-03-18T20:40:21.000Z",
      "isMaintainer": false
    }
  ],
  "mainBotCommentID": 1997845374,
  "ciResult": "pass"
}

@typescript-bot typescript-bot added Critical package Author is Owner The author of this PR is a listed owner of the package. Check Config Changes a module config files labels Mar 14, 2024
@typescript-bot
Copy link
Contributor

🔔 @ChristianMurphy @wooorm — please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

@typescript-bot
Copy link
Contributor

typescript-bot commented Mar 14, 2024

@remcohaszing Thank you for submitting this PR!

This is a live comment which I will keep updated.

1 package in this PR

Code Reviews

Because this is a widely-used package, a DT maintainer will need to review it before it can be merged.

You can test the changes of this PR in the Playground.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ✅ A DT maintainer needs to approve changes which affect module config files

All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 68955,
  "author": "remcohaszing",
  "headCommitOid": "d51924efb0e19162a72cc5cd33c738dae1ae6d8e",
  "mergeBaseOid": "55df51f723ed778b0960e1fe3ae43a3590a88d58",
  "lastPushDate": "2024-03-11T10:53:13.000Z",
  "lastActivityDate": "2024-03-22T10:52:38.000Z",
  "mergeOfferDate": "2024-03-22T00:06:29.000Z",
  "mergeRequestDate": "2024-03-22T10:52:38.000Z",
  "mergeRequestUser": "remcohaszing",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "mdx",
      "kind": "edit",
      "files": [
        {
          "path": "types/mdx/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/mdx/package.json",
          "kind": "package-meta-ok"
        },
        {
          "path": "types/mdx/preact-tests.tsx",
          "kind": "test"
        },
        {
          "path": "types/mdx/react-tests.tsx",
          "kind": "test"
        },
        {
          "path": "types/mdx/tsconfig.json",
          "kind": "package-meta-ok"
        },
        {
          "path": "types/mdx/tsconfig.preact.json",
          "kind": "package-meta",
          "suspect": "not [the expected form](https://github.com/DefinitelyTyped/DefinitelyTyped#user-content-tsconfigjson) (check: `compilerOptions.jsxFactory`)"
        },
        {
          "path": "types/mdx/tsconfig.react.json",
          "kind": "package-meta-ok"
        },
        {
          "path": "types/mdx/types.d.ts",
          "kind": "definition"
        }
      ],
      "owners": [
        "ChristianMurphy",
        "remcohaszing",
        "wooorm"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "jakebailey",
      "date": "2024-03-22T00:05:46.000Z",
      "isMaintainer": true
    },
    {
      "type": "approved",
      "reviewer": "ChristianMurphy",
      "date": "2024-03-18T20:40:21.000Z",
      "isMaintainer": false
    }
  ],
  "mainBotCommentID": 1997845374,
  "ciResult": "pass"
}

@typescript-bot
Copy link
Contributor

@jakebailey Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@typescript-bot
Copy link
Contributor

🔔 @ChristianMurphy @wooorm — please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

@typescript-bot
Copy link
Contributor

@jakebailey Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@weswigham
Copy link
Contributor

I'm pretty sure if you set jsxImportSource to preact, the preact example won't need anything special, type-wise, at least for "jsx": "react-jsx"

@remcohaszing
Copy link
Contributor Author

remcohaszing commented Mar 14, 2024

I'm pretty sure if you set jsxImportSource to preact, the preact example won't need anything special, type-wise, at least for "jsx": "react-jsx"

This used to be the case, but with frameworks moving away from the global JSX namespace, it no longer is.

Also DefinitelyTyped doesn’t allow specifying jsxImportSource. The classic runtime works for me so far, but maybe it should be allowed.

@remcohaszing
Copy link
Contributor Author

I also tried this:

declare module "mdx/types" {
    import { JSX } from 'preact/jsx-runtime'
}

but that gave the type error Imports are not permitted in module augmentations. Consider moving them to the enclosing external module.ts(2667)

@sheetalkamat
Copy link
Contributor

@jakebailey @sandersn @weswigham is this good to go or does this need some work as suggested by @weswigham in #68955 (comment) to support supplying jsxImportSource or similar ?

@jakebailey
Copy link
Member

This PR is fine from my perspective, I believe we were just waiting for feedback from other MDX maintainers.

Copy link
Contributor

@sheetalkamat sheetalkamat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking this as change needed so that its not on maintainer board. please merge main when one of MDX maintainer approves so we can approve this.

@typescript-bot typescript-bot added the Revision needed This PR needs code changes before it can be merged. label Mar 18, 2024
@typescript-bot
Copy link
Contributor

@remcohaszing One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits. Thank you!

@jakebailey
Copy link
Member

FWIW you can just move this over to the "needs review" column and it'll "bless" the PR to say "maintainer said okay", I'm pretty sure.

Copy link
Contributor

@ChristianMurphy ChristianMurphy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have access to the discord that initiated this PR to have the context.
Reading between the lines a bit, it seems to focus on adding preact testing?

I'm all for supporting the types of other frameworks.
But don't use them enough to offer much constructive review on this PR.
I'll approved to unblock if others are comfortable.

/cc @wooorm who have more thoughts on this

img: CustomImageComponent,
// @ts-expect-error
video: CustomImageComponent,
input: CustomImageComponent,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there something about input that makes it a better test than video?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, apparently input props are assignable to image props in Preact.

@jakebailey
Copy link
Member

I don't have access to the discord that initiated this PR to have the context.
Reading between the lines a bit, it seems to focus on adding preact testing?

The context is that I added to DT the ability to check with multiple different tsconfigs, which means projects can check with different settings and references. This was mainly for node to check with/without DOM types, but can also be used for MDX to test against react, preact, etc.

@ChristianMurphy
Copy link
Contributor

Thanks for the context @jakebailey! That helps

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem like there's going to be other feedback; going to approve this and you can feel free to merge if you believe that it's all good.

@typescript-bot typescript-bot added Owner Approved A listed owner of this package signed off on the pull request. Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner and removed Revision needed This PR needs code changes before it can be merged. labels Mar 22, 2024
@typescript-bot
Copy link
Contributor

@remcohaszing: Everything looks good here. I am ready to merge this PR (at d51924e) on your behalf whenever you think it's ready.

If you'd like that to happen, please post a comment saying:

Ready to merge

and I'll merge this PR almost instantly. Thanks for helping out! ❤️

(@ChristianMurphy, @wooorm: you can do this too.)

@remcohaszing
Copy link
Contributor Author

It looks like both Solid and Vue only work with the automatic runtime types, which are not allowed by dtslint. I’ll merge as-is.

@remcohaszing
Copy link
Contributor Author

Ready to merge

@typescript-bot typescript-bot merged commit a49cfed into DefinitelyTyped:master Mar 22, 2024
@remcohaszing remcohaszing deleted the mdx-test-real-frameworks branch March 22, 2024 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author is Owner The author of this PR is a listed owner of the package. Check Config Changes a module config files Critical package Maintainer Approved Owner Approved A listed owner of this package signed off on the pull request. Self Merge This PR can now be self-merged by the PR author or an owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants