-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Enhance how the Props type is used #366
Conversation
If the Props type isn’t defined, it now falls back to an empty shape instead of any. Also all keys are marked as readonly. As a result, props are no longer represented using the string `Props`, but an inline representation of the shape of the props. Given that the upcoming support for an MDX layout also requires a patched version of `Props`, this new setup is more consistent. Also the `props` description now contains a link to the props page on the MDX website.
🦋 Changeset detectedLatest commit: c7015d5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
' */', | ||
'export default function MDXContent(props) {', | ||
' return <>{Math.PI}</>', | ||
'}', | ||
'', | ||
'// @ts-ignore', | ||
'/** @typedef {Props} MDXContentProps */', | ||
'/** @typedef {0 extends 1 & Props ? {} : Props} MDXContentProps */', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{}
is not an empty object type, it is an any
type (minus null
and undefined
).
If you want to represent an empty object see https://github.com/sindresorhus/type-fest/blob/main/source/empty-object.d.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{}
is indeed not an object. It is an empty shape whose properties may be accessed, in other words, everything except null
or undefined
. Likewise { toString(): string }
is not an object, but a shape that has a toString()
method that returns string, in other words, pretty much everything except null
and undefined
.
To represent an actual object, the object
type can be used, or object & { someProprty: string }
. However, typically this doesn’t matter.
The goal here, and often with TypeScript, is not to ensure this is an empty object. It’s to ensure this is a shape whose properties may be accessed, even if it has no properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m going to merge this, because I really need this change. Feel free to open an issue if you strongly feel I’m wrong about this.
Initial checklist
Description of changes
If the Props type isn’t defined, it now falls back to an empty shape instead of any. Also all keys are marked as readonly. As a result, props are no longer represented using the string
Props
, but an inline representation of the shape of the props.Given that the upcoming support for an MDX layout also requires a patched version of
Props
, this new setup is more consistent.Also the
props
description now contains a link to the props page on the MDX website.