mojo.js
mojo.js copied to clipboard
Please document where to import Typescript types from
I am looking at mojo.js and exploring it as I look at a hobby project that needs something different from the content generators like Astro and Hugo that I've used in the past. So I am just starting to explore the tools documentation and capabilities. Right now I have the sample application generated by pnpm create @mojojs/full-app --ts:
import mojo, {yamlConfigPlugin} from '@mojojs/core';
export const app = mojo();
app.plugin(yamlConfigPlugin);
app.secrets = app.config.secrets;
app.get('/').to('example#welcome');
app.start();
and my eslint configuration is complaining that this has some unsafe defaults.
6:1 error Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment
10:1 error Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator @typescript-eslint/no-floating-promises
✖ 2 problems (2 errors, 0 warnings)
The second one was trivial to solve, I set my "module" option in tsconfig to "ESNext" and then added an "await" before app.start(). I admittedly do not fully understand all the implications of that change on performance.
The first one though is more of a challenge. The right solution appears to be to explicitly type the const app as something. vscodium and IntelJ IDEA. both infer that it is of type App but while vscodium is simply unable to suggest a place to import that definition from, IntelJ suggests '@mojojs/core/lib/app' except that does not appear to be a valid export.
Looking through the documentation I'm at a loss what the correct answer is. I strongly suspect this is a me problem and not a code problem, which is why I am requesting a paragraph or similar be added to the documentation to assist new adopters figure out things like this as they get themselves started.
Thanks!!
While we do our best to support TypeScript, we make no attempt at trying to teach it. That is simply out of scope for the documentation as it is not our area of expertise. But we are happy to consider any concrete improvements to the documentation you might propose.
Not asking for a teacher, I can program at a beginner's level acceptably enough (for my goals so far), but code diving an unfamiliar code base to find out what's exported where is a bit of a challenge for me. That's more the improvement I'm asking for. A pointer on where your exports are.
- For example, when I was learning Astro, their documentation includes example import lines in most of the code examples, such as https://docs.astro.build/en/guides/content-collections/#defining-a-collection-schema
- Alternately, for a lower level of effort, but still meeting my needs adequately, nearly all of Tabulator's examples are in javascript, just as yours are, but they include a short blurb on installing the typings.
I'm not asking for a full typescript tutorial, just a pointer towards the right things to import. Thanks for your time and effort on a community project :-)
Apparently in my specific example of class App in the tutorial code, import { type App} from '@mojojs/core/lib/app'; (which is what I hit) but importing App as a class from that location works - and serves the purpose. And as you said, explaining when importing by type versus the class itself its outside the scope of mojo.js and something I can find in general typescript documentation.