stalniy/bdd-lazy-var

how can I use it in typescripts?

Closed this issue · 4 comments

how can I use it in typescripts?

Currently there are no typings for typescript but I will try to add them :)

Thanks for the issue

Published 2.2.2 which contains typings for Typescript.

If you import some interface using ES6 loaders then nothing else is required. If you use commonjs style for your tests then use add the typings for corresponding interface in tsconfig.json

For example:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "removeComments": true,
    "preserveConstEnums": true
  },
  "include": [
    "./node_modules/bdd-lazy-var/getter.d.ts"
   // or index
    "./node_modules/bdd-lazy-var/index.d.ts"
   // or global
    "./node_modules/bdd-lazy-var/global.d.ts"
  ]
}

As bdd-lazy-var/global defines global getters I can't let typescript to detect this automatically. So, you will need manually add them using declare. For example:

// don't forget to add bdd-lazy-var/global.d.ts into tsconfig.json

describe('Test', () => {
  declare const $value: number; // <-- this is required and should be done manually
  def('value', () => 5)

  it('works', () => {
    expect($value).to.equal(5)
  })
})

So, if you prefer typescript in tests I'd suggest to user getter syntax. It's still clean enough but will not require you manually add declare const $value: number.

Cheers!

Will add this later into README docs

Thanks for the issue 👍