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 global typings for extensions #2992

Merged
merged 14 commits into from
Aug 19, 2021
Merged

Fix global typings for extensions #2992

merged 14 commits into from
Aug 19, 2021

Conversation

davwheat
Copy link
Member

@davwheat davwheat commented Jul 30, 2021

Fixes #2963

Changes proposed in this pull request:

  • Adds support for our global typings in extensions
  • Linked tsconfig PR sets up this configuration
  • Drops global app typings (people should import instead)
  • Adds common namespace app export
  • Adds missing app imports to core
  • Converts Mithril imports within core to type imports (causes error if we attempt to use the imported mithril for anything except types as this causes duplicated code)
  • Adds typings for global flarum variable

Reviewers should focus on:

To test this locally...

  1. Require this branch in an extension's composer.json
  2. composer update
  3. cd vendor/flarum/core/js
  4. npm i
  5. npm run build-typings
  6. Modify extension's tsconfig.json as per Add configuration for global typings flarum-tsconfig#2
  7. Test global typings! (dayjs, mithril)

Screenshot

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).

Required changes:

@davwheat davwheat added this to the 1.0.5 milestone Jul 30, 2021
@davwheat davwheat self-assigned this Jul 30, 2021
@davwheat davwheat marked this pull request as ready for review July 30, 2021 12:24
Copy link
Member

@askvortsov1 askvortsov1 left a comment

Choose a reason for hiding this comment

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

Not tested locally, but generally LGTM. Solid set of changes!

Left a few nits.

js/src/@types/global.d.ts Outdated Show resolved Hide resolved
js/src/@types/global.d.ts Show resolved Hide resolved
@SychO9 SychO9 modified the milestones: 1.0.5, 1.1 Aug 15, 2021
Co-authored-by: Alexander Skvortsov <sasha.skvortsov109@gmail.com>
davwheat added a commit to flarum/flarum-tsconfig that referenced this pull request Aug 15, 2021
@SychO9 SychO9 self-requested a review August 18, 2021 11:38
@SychO9
Copy link
Member

SychO9 commented Aug 18, 2021

Weird 🤔, compiling with this seems to break extensions that use TS but don't import app.
app points to flarum.core.app.

Uncaught TypeError: Cannot read property 'addTranslations' of undefined
Uncaught TypeError: flarum.core.app.load is not a function

@davwheat
Copy link
Member Author

davwheat commented Aug 18, 2021

Hmm... Typing changes couldn't do that as that's handled by the webpack config... Which extension is this?

@SychO9
Copy link
Member

SychO9 commented Aug 18, 2021

never mind, it doesn't have anything to do with extensions, just checking out this branch and building dist files results in the error above. could it be the ../common/app imports ? how does that point to Application ?

@davwheat
Copy link
Member Author

davwheat commented Aug 18, 2021

It doesn't. In my testing, returning window.app seemed to work fine. Might have to revisit that in that case.

My thinking was that the app instances are created by the forum/admin exports, and overwriting them with a Common app would be disastrous.

@davwheat davwheat merged commit 2831ce2 into master Aug 19, 2021
@davwheat davwheat deleted the dw/fix-global-typings branch August 19, 2021 09:10
askvortsov1 pushed a commit to flarum/flarum-tsconfig that referenced this pull request Mar 11, 2022
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.

Globals variables ($, dayjs) are not correctly type-hinted
3 participants