Dynamoose: Typescript usage with dynamoose namespace

Created on 17 Jun 2019  路  3Comments  路  Source: dynamoose/dynamoose

Summary:

New to typescript (leaving flow) and somewhat dynamoose so this may be a simple question, but how do you assign dynamoose as a type? This is specifically for when dynamoose is passed in as a dependency. I can access some type exports such as Model, Schema, Table etc. but looking through the dynamoose.d.ts file I ses no actual dynamoose type. Am I missing something?

Code sample:

This is what I'm trying to achieve.

import Dynamoose from 'dynamoose'

type Options = {
  dynamoose: Dynamoose,
}

const provider = ({ dynamoose }: Options) => {...}

Current output and behavior:

I'm currently getting TS errors as follows:

Cannot use namespace 'Dynamoose' as a type.ts(2709)
Property 'dynamoose' of exported interface has or is using private name 'Dynamoose'.ts(4033)

Expected output and behavior:

To get typings for the Dynamoose object.

Environment:

Operating System:
Operating System Version: MacOS 10.14.x
Node.js version (node -v): 8.12.0
NPM version: (npm -v): 6.4.1
Dynamoose version: 1.8.0
Dynamoose Plugins: n/a

Dynamoose Plugins:

  • [ ] Yes, I believe that one or multiple 3rd party Dynamoose plugins are effecting this issue
  • [ ] No, I believe this issue is independent of any 3rd party Dynamoose plugins I'm using
  • [ ] Unknown, I'm unsure if Dynamoose plugins are effecting this issue
  • [x] I am not using any Dynamoose plugins

### Other information (if applicable):
-

Type (select 1):

  • [ ] Bug report
  • [ ] Feature suggestion
  • [x] Question
  • [ ] Other suggestion
  • [ ] Something not listed here

Other:

  • [x] I have read through the Dynamoose documentation before posting this issue
  • [x] I have searched through the GitHub issues (including closed issues) and pull requests to ensure this issue has not already been raised before
  • [x I have searched the internet and Stack Overflow to ensure this issue hasn't been raised or answered before
  • [x] I have tested the code provided and am confident it doesn't work as intended
  • [ ] I have ensured that all of my plugins that I'm using with Dynamoose are listed above
  • [x] I have filled out all fields above
  • [x] I am running the latest version of Dynamoose

Most helpful comment

I fixed this issue in my project by defining Dynamoose type like this: type Dynamoose = typeof dynamoose

All 3 comments

I fixed this issue in my project by defining Dynamoose type like this: type Dynamoose = typeof dynamoose

Thanks @dolsem I've got that working now - much appreciated!

I've opened a request to fix issues like these in TypeScript by bringing declaration files to parity with language features. https://github.com/microsoft/TypeScript/issues/35822

Was this page helpful?
0 / 5 - 0 ratings

Related issues

androidand picture androidand  路  3Comments

brennhill picture brennhill  路  10Comments

AllanOricil picture AllanOricil  路  4Comments

arifsetyawan picture arifsetyawan  路  8Comments

mcalhoun picture mcalhoun  路  6Comments