Barba: TypeScript build error when using the `.hooks` syntax

Created on 15 Nov 2019  Â·  6Comments  Â·  Source: barbajs/barba

The problem

I get an error when building a TypeScript file with @barba/core 2.7.0 or later:

ERROR in /home/hugo/Documents/Git/Calinou/godot-asset-library-laravel/resources/ts/app.ts
./resources/ts/app.ts
[tsl] ERROR in /home/hugo/Documents/Git/Calinou/godot-asset-library-laravel/resources/ts/app.ts(168,1)
      TS2722: Cannot invoke an object which is possibly 'undefined'.

ERROR in /home/hugo/Documents/Git/Calinou/godot-asset-library-laravel/resources/ts/app.ts
./resources/ts/app.ts
[tsl] ERROR in /home/hugo/Documents/Git/Calinou/godot-asset-library-laravel/resources/ts/app.ts(173,1)
      TS2722: Cannot invoke an object which is possibly 'undefined'.

The script is available here:
https://github.com/Calinou/godot-asset-library-laravel/blob/master/resources/ts/app.ts

Description

Details

This doesn't happen with version 2.6.1 or earlier. I was able to upgrade to 2.8.0 by changing the hooks syntax to the object-based one, but I feel like it's worth reporting it here.

Expected behaviour

It builds successfully (as long as this syntax is still supported) :slightly_smiling_face:

Actual behaviour

I get a build error (due to TypeScript).

Environment

  • Barba version that exhibits the issue: 2.7.0 and later
  • Build used:

    • [x] module (esm/)

    • [ ] browser (dist/)

    • [ ] main (lib/)

  • Browser OS/version used: Node.js 12.6.0, TypeScript 3.7.2
bug v2

All 6 comments

@Calinou Fix on his way.
I will probably release an @next version tonight and keep you informed…

@Calinou could you try with @next release (https://www.npmjs.com/package/@barba/core/v/2.9.0) ?
Thanks in advance!

@thierrymichel No dice :slightly_frowning_face: I removed my node_modules folder after setting the version to 2.9.0 in package.json to rule out caching issues, but I still get the same error.

That said, I noticed assigning the hook to an anonymous function (instead of calling it as a function) works fine:

barba.hooks.leave = () => {
  // ...
};

barba.hooks.after = () => {
  // ...
};

Either way, it's a not a huge issue to me, I can switch to whichever syntax works best.

@Calinou One more time? (2.9.1)
Sorry for the inconvenience… 😊

@Calinou 2.9.2 should be even better regarding TypeScript definitions (I do not know how you manage it…) :)

@thierrymichel It works in both 2.9.1 and 2.9.2, thanks :slightly_smiling_face:

Was this page helpful?
0 / 5 - 0 ratings