feathersjs-ecosystem / feathers-blob

Feathers service for blob storage, like S3.
http://feathersjs.com
MIT License
92 stars 32 forks source link

Typescript: Cannot use namespace 'AbstractBlobStore' as a type #81

Closed green3g closed 3 years ago

green3g commented 3 years ago

Steps to reproduce

Using files.service.ts like so:

// Initializes the `files` service on path `/api/v1/files`
import { ServiceAddons } from '@feathersjs/feathers';
import BlobService from 'feathers-blob';
import multer from 'multer';
import { Application } from '../../declarations';
import logger from '../../logger';
import hooks from './files.hooks';

interface Data { }

interface ServiceOptions { }

// Add this service to the service type index
declare module '../../declarations' {
    interface ServiceTypes {
        'api/v1/files': ServiceAddons<any>;
    }
}

const log = (msg) => logger.info('[File Service]: ' + msg)

const multipartMiddleware = multer();

export default function (app: Application) {
    const storeOptions = app.get('blobStore');

    let store;
    if (storeOptions.type === 'local') {
        log('Creating new local blob store:' + storeOptions.path)
        const BlobStore = require('fs-blob-store');
        store = BlobStore(storeOptions.path);
    } else if (storeOptions.type === 's3') {
        const AWS = require('aws-sdk');
        const BlobStore = require('s3-blob-store')
        log('Creating new s3 blob store:' + storeOptions.bucket)
        AWS.config.update(storeOptions);

        const s3 = new AWS.S3();
        store = new BlobStore({
            client: s3,
            bucket: storeOptions.bucket,
        });
    }

    const Files = new (BlobService as any)({
        Model: store,
    })

    app.use('/api/v1/files',

        // multer parses the file named 'uri'.
        // Without extra params the data is
        // temporarely kept in memory
        multipartMiddleware.single('uri'),

        // another middleware, this time to
        // transfer the received file to feathers
        function (req: any, res: any, next) {
            req.feathers.file = req.file;
            next();
        },

        Files,
    );

    // Get our initialized service so that we can register hooks
    const service = app.service('api/v1/files');

    service.hooks(hooks);
}

running tsc from the npm run compile command gives this error.

    "compile": "rm -rf lib/ && tsc"

(First please check that this issue is not already solved as described here)

Expected behavior

Feathers blob works with typescript

Actual behavior

node_modules/feathers-blob/types/index.d.ts:34:12 - error TS2709: Cannot use namespace 'AbstractBlobStore' as a type.

34     Model: AbstractBlobStore;
              ~~~~~~~~~~~~~~~~~

Found 1 error.

System configuration

Tell us about the applicable parts of your setup.

Module versions (especially the part that's not working):

{
  "name": "wsb-services-ts",
  "description": "wsb rest services in typescript",
  "version": "0.0.0",
  "homepage": "",
  "private": true,
  "main": "src",
  "keywords": [
    "feathers"
  ],
  "author": {
    "name": "groemhildt",
    "email": "groemhildt@wsbeng.com"
  },
  "contributors": [],
  "bugs": {},
  "directories": {
    "lib": "src",
    "test": "test/",
    "config": "config/"
  },
  "engines": {
    "node": "^14.0.0",
    "npm": ">= 3.0.0"
  },
  "scripts": {
    "test": "npm run lint && npm run compile && npm run jest",
    "lint": "eslint src/. test/. --config .eslintrc.json --ext .ts --fix",
    "dev:api": "ts-node-dev --no-notify src/",
    "dev:jobs": "ts-node-dev ${TS_ARGS} --no-notify src/jobs/",
    "start": "node lib/",
    "start:jobs": "node lib/jobs/",
    "jest": "jest  --forceExit",
    "compile": "rm -rf lib/ && tsc"
  },
  "standard": {
    "env": [
      "jest"
    ],
    "ignore": []
  },
  "dependencies": {
    "@feathersjs/authentication": "^4.5.10",
    "@feathersjs/authentication-client": "^4.5.10",
    "@feathersjs/authentication-local": "^4.5.10",
    "@feathersjs/authentication-oauth": "^4.5.10",
    "@feathersjs/configuration": "^4.5.10",
    "@feathersjs/errors": "^4.5.10",
    "@feathersjs/express": "^4.5.10",
    "@feathersjs/feathers": "^4.5.10",
    "@feathersjs/rest-client": "^4.5.10",
    "@feathersjs/socketio": "^4.5.10",
    "@feathersjs/transport-commons": "^4.5.10",
    "@wsb/report-services": "^2.2.0",
    "aws-sdk": "^2.790.0",
    "bull": "^3.18.1",
    "compression": "^1.7.4",
    "cookie-parser": "^1.4.5",
    "cors": "^2.8.5",
    "dauria": "^2.0.0",
    "feathers-blob": "^2.3.0",
    "feathers-objection": "^6.3.0",
    "feathers-swagger": "^1.2.1",
    "fs-blob-store": "^5.2.1",
    "helmet": "^4.2.0",
    "http-proxy-middleware": "^1.0.6",
    "isomorphic-fetch": "^3.0.0",
    "knex": "^0.21.12",
    "lodash.omit": "^4.5.0",
    "multer": "^1.4.2",
    "objection": "^2.2.3",
    "pg": "^8.5.0",
    "s3-blob-store": "^4.1.1",
    "serve-favicon": "^2.5.0",
    "tmp-promise": "^3.0.2",
    "winston": "^3.3.3"
  },
  "devDependencies": {
    "@types/bull": "^3.14.4",
    "@types/compression": "^1.7.0",
    "@types/cookie-parser": "^1.4.2",
    "@types/cors": "^2.8.8",
    "@types/helmet": "^4.0.0",
    "@types/jest": "^26.0.15",
    "@types/jsonwebtoken": "^8.5.0",
    "@types/lodash.omit": "^4.5.6",
    "@types/multer": "^1.4.4",
    "@types/serve-favicon": "^2.5.1",
    "@typescript-eslint/eslint-plugin": "^4.7.0",
    "@typescript-eslint/parser": "^4.7.0",
    "axios": "^0.21.0",
    "eslint": "^7.13.0",
    "jest": "^26.6.3",
    "shx": "^0.3.3",
    "ts-jest": "^26.4.4",
    "ts-node-dev": "^1.0.0",
    "typescript": "^4.0.5"
  }
}

NodeJS version: 14.14.0 Operating System: MacOS Browser Version: Firefox

❯ tsc --version
message TS6029: Version 1.5.3
green3g commented 3 years ago

After manually installing abstract-blob-store in npm package.json, the error went away.