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

fix: react macro types #1620

Merged
merged 2 commits into from
Apr 28, 2023
Merged

fix: react macro types #1620

merged 2 commits into from
Apr 28, 2023

Conversation

vonovak
Copy link
Collaborator

@vonovak vonovak commented Apr 26, 2023

Description

improves macro TS typings

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Fixes # (issue)

Checklist

  • I have read the CONTRIBUTING and CODE_OF_CONDUCT docs
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

@vercel
Copy link

vercel bot commented Apr 26, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
js-lingui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 28, 2023 8:24am

? { [P in K]?: T[K] } & Partial<Record<Exclude<keyof T, K>, never>>
: never

export type TransRenderCallbackOrComponent =
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

works the same as before but is a little simpler in terms of TS

had to name it so that it can be imported in macro typings.. maybe it could be renamed to something else so that it's not considered as stable public api..

Comment on lines +37 to +38
const values = { ...props.values }
const components = { ...props.components }
Copy link
Collaborator

Choose a reason for hiding this comment

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

it is because "undefined" could be also spread to the object?


export function Trans(props: TransProps): React.ReactElement<any, any> | null {
const { i18n, defaultComponent } = useLingui()
const { render, component, id, message, formats } = props

const values = { ...(props.values || {}) }
const components = { ...(props.components || {}) }
const values = { ...props.values }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

spreading both null and undefined is valid so this works the same

id?: string
comment?: string
context?: string
render?: (props: TransRenderProps) => ReactElement<any, any> | null
i18n?: I18n
Copy link
Collaborator Author

@vonovak vonovak Apr 26, 2023

Choose a reason for hiding this comment

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

i18n was added in #1308

I tested it and (1) doesn't work (2) isn't documented and right now it's easier to remove it

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, i also spotted it there, and wrote an issue to clatify this #1433

@github-actions
Copy link

github-actions bot commented Apr 26, 2023

size-limit report 📦

Path Size
./packages/core/dist/index.mjs 1.43 KB (0%)
./packages/detect-locale/dist/index.mjs 721 B (0%)
./packages/react/dist/index.mjs 1.6 KB (0%)
./packages/remote-loader/dist/index.mjs 7.24 KB (0%)

@codecov
Copy link

codecov bot commented Apr 26, 2023

Codecov Report

Patch coverage: 74.54% and project coverage change: +3.17 🎉

Comparison is base (6459f02) 72.22% compared to head (1c49b1f) 75.40%.

❗ Current head 1c49b1f differs from pull request most recent head 8670e3e. Consider uploading reports for the commit 8670e3e to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1620      +/-   ##
==========================================
+ Coverage   72.22%   75.40%   +3.17%     
==========================================
  Files          72       77       +5     
  Lines        2459     1988     -471     
  Branches      708      517     -191     
==========================================
- Hits         1776     1499     -277     
+ Misses        536      375     -161     
+ Partials      147      114      -33     
Impacted Files Coverage Δ
packages/cli/src/api/extractors/typescript.ts 0.00% <0.00%> (-9.38%) ⬇️
packages/cli/src/api/stats.ts 90.00% <ø> (+20.00%) ⬆️
packages/cli/src/lingui.ts 0.00% <0.00%> (ø)
packages/cli/src/services/translationIO.ts 0.00% <0.00%> (ø)
packages/cli/src/lingui-extract.ts 18.60% <20.00%> (+18.60%) ⬆️
packages/cli/src/lingui-compile.ts 29.62% <29.16%> (-0.96%) ⬇️
packages/cli/src/api/formats/index.ts 42.85% <50.00%> (-17.15%) ⬇️
packages/cli/src/api/help.ts 60.00% <50.00%> (+50.00%) ⬆️
...ges/cli/src/extract-experimental/getEntryPoints.ts 50.00% <50.00%> (ø)
packages/cli/src/lingui-extract-template.ts 55.00% <60.00%> (+55.00%) ⬆️
... and 28 more

... and 42 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@andrii-bodnar andrii-bodnar changed the base branch from next to main April 26, 2023 10:03
@andrii-bodnar andrii-bodnar merged commit 8a48b9f into lingui:main Apr 28, 2023
12 checks passed
@vonovak vonovak deleted the fix/react-types branch April 28, 2023 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants