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

Typescript Intellisense #19

Closed
linonetwo opened this issue Apr 11, 2019 · 7 comments
Closed

Typescript Intellisense #19

linonetwo opened this issue Apr 11, 2019 · 7 comments
Labels
question Not a true issue, usually a question relating to usage.

Comments

@linonetwo
Copy link

Is it possible to add typing so it reflects it is a function parameter?

@haltcase haltcase added the question Not a true issue, usually a question relating to usage. label Apr 11, 2019
@haltcase
Copy link
Owner

haltcase commented Apr 11, 2019

You'll have to write a declaration file, something like this:

declare module 'param.macro' {
  export const _: any
  export const it: (...args: any[]) => any
  export const lift: (expr: any) => (...args: any[]) => any
}

I don't imagine this would be useful for type info but maybe for usability purposes it's ok.

@haltcase
Copy link
Owner

Feel free to discuss but I'm going to close since this is currently outside the scope of the project.

@ghalex
Copy link

ghalex commented May 6, 2019

Hi @citycide I still don't understand how should we use this with Typescript. I tried this:

const item = {id: 2}
const arr = [{id: 1}, {id: 2}]
const ndx = arr.findIndex(it.id === item.id);

gives me an error of:
Argument of type 'boolean' is not assignable to parameter of type ...

Do I miss something here ?

@haltcase
Copy link
Owner

haltcase commented May 6, 2019

@ghalex it's highly unlikely there's any typing you'll be able to do that will give you the full range of features, unfortunately. We'll need TypeScript compiler extensions most likely and there's nothing official for that right now.

The problem in your case is that findIndex is typed as expecting something like (el: T, i: number, arr: T[]) => boolean and you're simply passing an expression that evaluates to boolean (=== equality). There's currently no way of telling TypeScript that param.macro transforms that expression into the kind of function findIndex expects.

I'm happy to accept changes here that make TypeScript support possible but I don't think it'll be easy.

@LifeIsStrange
Copy link

@haltcase That's very unfortunate to hear, I hope the situation will improve eventually. The world is moving to typescript (BTW kotlin js now generate d.ts files !)
It seems that it is possible to create compiler plugins:
https://www.typescriptlang.org/tsconfig#plugins

@haltcase
Copy link
Owner

@LifeIsStrange I agree, I have also personally switched to TypeScript for many projects and miss param.macro every time 😄

I'm fairly certain a compiler plugin would be capable of this, but as far as I know this currently requires a separate wrapper around the compiler to enable their use in most cases, see ttypescript. I've considered doing this but have not explored the compiler API enough.

@linonetwo
Copy link
Author

linonetwo commented Feb 22, 2022

Wait...Are you talking about using param.macro in the TS project?

AFAIK macro works well in the TS, as long as you are using babel + ts , see https://github.com/linonetwo/template-based-generator-template/blob/master/src/data/index.ts for an example!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Not a true issue, usually a question relating to usage.
Projects
None yet
Development

No branches or pull requests

4 participants