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

Please document where to import Typescript types from #142

Open
lschierer opened this issue Jul 12, 2024 · 3 comments
Open

Please document where to import Typescript types from #142

lschierer opened this issue Jul 12, 2024 · 3 comments

Comments

@lschierer
Copy link

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!!

@kraih
Copy link
Member

kraih commented Jul 12, 2024

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.

@lschierer
Copy link
Author

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.

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 :-)

@lschierer
Copy link
Author

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.

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

No branches or pull requests

2 participants