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

Writing preval files in TypeScript #106

Open
alexgleason opened this issue May 26, 2022 · 3 comments
Open

Writing preval files in TypeScript #106

alexgleason opened this issue May 26, 2022 · 3 comments

Comments

@alexgleason
Copy link

When using // @preval at the top of the file, it's first evaluated in Node.js. This means that TypeScript has no idea what's going on. If I leave these files as vanilla JS (.js) it's okay (the import gets an any type in TS), but then we don't get the advantages of TypeScript.

Can I write preval files themselves in TypeScript? Maybe with ts-node?

@alexgleason
Copy link
Author

@mpeyper since you converted this repo to TypeScript in #86... do you know if this is possible?

@mpeyper
Copy link
Contributor

mpeyper commented Nov 4, 2022

Sorry, I’m not sure.

It might be possible to support processing of preval snippets with ts, but I think having the resulting types pass through to other code trying to use the output would be quite difficult, if not impossible.

@pedromchd
Copy link

Hey, I'm trying to use preval with Expo/Typescript, but I can't get properly typing assertion and indexing, is there any solution to this?

// babel.config.js
module.exports = function (api) {
  api.cache(true);
  return {
    presets: [['babel-preset-expo', { jsxImportSource: 'nativewind' }], 'nativewind/babel'],
    plugins: ['babel-plugin-preval'],
  };
};

I created a d.ts file, but doesn't cover such things as preval.require:

// preval.d.ts
declare function preval(strings: TemplateStringsArray): any;

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

3 participants