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

Could you create @types for this module? #98

Closed
scottge opened this issue Jan 10, 2019 · 9 comments
Closed

Could you create @types for this module? #98

scottge opened this issue Jan 10, 2019 · 9 comments

Comments

@scottge
Copy link

scottge commented Jan 10, 2019

Could you create @types for this module so that it can be easily used in typescript?

@oott123
Copy link
Contributor

oott123 commented Jan 10, 2019

+1 for type definition files, and there are some useful links for you @harttle :

http://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html

http://definitelytyped.org/guides/best-practices.html

As the author of liquidjs, you can just add a file named like index.d.ts in your package and add a field named types point to that file, without having knownledge to definitelytyped. The link provide above is a guide for you to create high-quality type definitions.

@harttle
Copy link
Owner

harttle commented Jan 10, 2019

A index.d.ts from @oott123 has been merged and published @6.2.0, try it!
If you still got problems, any revision is welcome. I'm not closing this issue for now.

@scottge
Copy link
Author

scottge commented Jan 10, 2019

Excellent!!! :)

A few types are still missing:

tagToken: any
remainTokens: any
scope: any
hash: any

I also don't think 'void' is the right return type for render.. According to https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers#rendering, render is supposed to return a string.

Thanks to your types, I can finally implement tag using this kind of code:

class HighlightTagImpl implements Liquid.Tag {
  parse(tagToken: any, remainTokens: any): void {
    throw new Error('Method not implemented.')
  }
  render(scope: any, hash: any): void {
    throw new Error('Method not implemented.')
  }
}

engine.registerTag('highlight', new HighlightTagImpl())

@scottge
Copy link
Author

scottge commented Jan 11, 2019

Update: the type definition is giving the following error.

Here is how I import it in typescript:

import Liquid, { LiquidEngine } from 'liquidjs'

Here is how I use it in my typescript code:

class MyClass {
    private engine: LiquidEngine
    public constructor() {
        this.engine = Liquid()
    }
}

Here is the error I receive:

TSError: ⨯ Unable to compile TypeScript:
error TS1192: Module '"/node_modules/liquidjs/src/index"' has no default export.

@scottge
Copy link
Author

scottge commented Jan 11, 2019

It turns that I MUST use import Liquid = require('liquidjs') to import the module in order for it to work. I cannot do import from.

@oott123
Copy link
Contributor

oott123 commented Jan 11, 2019

Liquidjs is not a es module, so that you may HAVE to use the require form instead of regular import syntax. However, these types have some errors and I have no time to fix it. Maybe someone can take over it.

harttle added a commit that referenced this issue Feb 13, 2019
The demo is located at demo/typescript/index.ts , working on #98
harttle pushed a commit that referenced this issue Feb 13, 2019
## [6.4.3](v6.4.2...v6.4.3) (2019-02-13)

### Bug Fixes

* better index.d.ts and a demo ([2015f68](2015f68)), closes [#98](#98)
@harttle
Copy link
Owner

harttle commented Feb 13, 2019

I cannot do import from.

Now it should work, there's an demo located at demo/typescript/index.ts. Definitions for tagToken, remainTokens, scope, hash, etc are still not available, but maybe added latter.

Let me know if you have problems with the demo.

@scottge
Copy link
Author

scottge commented Feb 18, 2019

Types seems broken in the latest 7.0 release? My ts project is complaining that could not find a declaration file for liquidjs.

@harttle
Copy link
Owner

harttle commented Feb 20, 2019

Now it's fixed @7.0.1 and all methods should be typed already. Closing.

@harttle harttle closed this as completed Feb 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants