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: Type 'string' is not assignable to type 'FieldType'. influx@next #343

Open
shadow1349 opened this issue Feb 5, 2019 · 3 comments

Comments

@shadow1349
Copy link

I am trying to use influx with my typescript/express app, but I cannot assign any strings in fields. here is my example:

import * as influx from 'influx';
import { Request, Response, NextFunction } from 'express';
import * as os from 'os';

const Influx = new influx.InfluxDB({
  host: 'host',
  database: 'my_database',
  schema: [
    {
      measurement: 'express_response_times',
      fields: {
        path: influx.FieldType.STRING,
        duration: influx.FieldType.INTEGER
      },
      tags: ['host']
    }
  ]
});

export const ExpressTimer = function(req: Request, res: Response, next: NextFunction) {
  const start = Date.now();

  res.on('finish', () => {
    const duration = Date.now() - start;

    Influx.writePoints([
      {
        measurement: 'express_response_times',
        tags: { host: os.hostname() },
        fields: { duration, path: req.path }, //path gets the red underline with the error Type 'string' is not assignable to type 'FieldType'.
        timestamp: Date.now()
      }
    ]);
  });

  return next();
};

If I change path to be a number everything works fine, but because fields has type { [name: string]: influx.FieldType } and FieldType is an enum only numbers are assignable in fields when using typescript.

This is an issue when using influx@next, in the current stable version 5.0.7 FieldMap is used instead and is a type, but this issue should be addressed in the @next version.

export declare type FieldMap = {
    [name: string]: string | number | boolean;
};
@stale
Copy link

stale bot commented Jun 1, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 1, 2019
@stale
Copy link

stale bot commented Aug 3, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 3, 2019
@stale stale bot closed this as completed Aug 10, 2019
@bencevans bencevans reopened this Aug 27, 2020
@stale stale bot removed the stale label Aug 27, 2020
@hsiaosiyuan0
Copy link

I met this issue while following the official guide https://node-influx.github.io, it looks like the guide is neglected

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