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 error #92

Open
aarongreenwald opened this issue Feb 21, 2019 · 3 comments
Open

Typescript error #92

aarongreenwald opened this issue Feb 21, 2019 · 3 comments

Comments

@aarongreenwald
Copy link

Starting today, apparently with the release of v1.1.0, we started getting the following error when running TS compilation on our project that uses lru-memoize:

node_modules/lru-memoize/dist/index.d.ts:1:25 - error TS1254: A 'const' initializer 
in an ambient context must be a string or numeric literal or literal enum reference.

  1 declare const memoize = (
                            ~
  2   limit?: number,
    ~~~~~~~~~~~~~~~~~
...
  4   deepObjects?: boolean
    ~~~~~~~~~~~~~~~~~~~~~~~
  5 ) => <T extends Function>(func: T) => T;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/lru-memoize/dist/index.d.ts:5:39 - error TS2693: 'T' only refers to a type, 
but is being used as a value here.

5 ) => <T extends Function>(func: T) => T;
                                        ~


Found 2 errors.

Our tsconfig.json looks like this:

{
  "compilerOptions": {
    "declaration": true,
    "allowJs": false,
    "target": "ESNEXT",
    "module": "commonjs",
    "noImplicitAny": false,
    "noImplicitThis": false,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "lib": ["es2015", "es2017.object"],
    "outDir": "./lib"
  },
  "exclude": [
    "node_modules",
    "dist",
    "test"
  ]
}

Any ideas what we're doing wrong? When I downgrade to version 1.0.2 of lru-memoize everything works.

@KhodeN
Copy link

KhodeN commented Feb 22, 2019

May be the right way is

declare const memoize : (
  limit?: number,
  ...

or even

export default function memoize(
  limit?: number,
  equals?: (a: any, b: any) => boolean,
  deepObjects?: boolean
) => <T extends Function>(func: T) => T;

@johnryan
Copy link

Any update on this?

@airhorns
Copy link

airhorns commented May 13, 2019

@KhodeN is right on, this type definition is working fine for me:

declare module "lru-memoize" {
  function Memoizer(
    limit?: number,
    equals?: (a: any, b: any) => boolean,
    deepObjects?: boolean
  ): <T extends (...args: any[]) => any>(func: T) => (...funcArgs: Parameters<T>) => ReturnType<T>;
  export default Memoizer;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants