1

I'm trying to use collections/sorted-map in my React TS project. sorted-map doesn't have a declaration. I found out that I need to create my own sorted-map.d.ts declaration (React, Typescript - Cannot find module ... or its corresponding type declarations).

Luckily there is a declaration for sorted-set which is part of sorted-map so it should be relatively easy.

The problem is - even after creating sorted-map.d.ts I still get the same error:

Cannot find module 'collections/sorted-map' or its corresponding type declarations.ts(2307)

Sandbox

src/sorted-map.d.ts:

import {SortedSet} from "collections/sorted-set"

declare module 'collections/sorted-map'
// declare const SortedMap: internal.SortedMapStatic;

declare namespace SortedMap {
    type Iterator<T> = internal.Iterator<T>;
    type SortedMap<T> = internal.SortedMap<T>;
}

declare namespace internal {
    interface SortedMapStatic {
        <T>(
            values?: T[],
            equals?: (a: T, b: T) => boolean,
            compare?: (a: T, b: T) => number,
            getDefault?: any,
        ): SortedMap<T>;
        new <T>(
            values?: T[],
            equals?: (a: T, b: T) => boolean,
            compare?: (a: T, b: T) => number,
            getDefault?: any,
        ): SortedMap<T>;
    }

    class Iterator<T> {
        constructor(set: SortedMap<T>, start?: T, end?: T);
        next(): { done: boolean; value: T | undefined };
    }

    class SortedMap<T> {
        readonly length: number;

        constructor(values?: T[], equals?: (a: T, b: T) => boolean, compare?: (a: T, b: T) => number, getDefault?: any);
        constructClone(values?: T[]): SortedMap<T>;
        iterate(): Iterator<T>;
        store: SortedSet<T>;
    }
}

export = SortedMap;

App.tsx:

import { SortedMap } from "collections/sorted-map";

export default function App() {
  return <div>Test</div>;
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.