earthstar-project / earthstar

Storage for private, distributed, offline-first applications.
https://earthstar-project.org
GNU Lesser General Public License v3.0
623 stars 18 forks source link

Error compiling typescript file that imports earthstar npm package #331

Open michielbdejong opened 1 month ago

michielbdejong commented 1 month ago

Any pointers on how to use the earthstar npm package in a node-typescript project? This is how far I got:

mkdir test
cd test
npm install earthstar
cat << EOF > test.ts
import {
  ExtensionKnownShares,
  ExtensionSyncWeb,
  Replica,
  ReplicaDriverFs,
  Server,
} from "earthstar";
import { createServer } from "http";

const nodeServer = createServer();

const server = new Server([
  new ExtensionKnownShares({
    // known_shares.json contains a JSON array of public share addresses.
    knownSharesPath: "./known_shares.json",
    // Persist share data to disk with ReplicaDriverFs
    onCreateReplica: (shareAddress) => {
      return new Earthstar.Replica({
        driver: new ReplicaDriverFs(shareAddress, "./share_data"),
      });
    },
  }),
  new ExtensionSyncWeb({ server: nodeServer }),
], { server: nodeServer });
EOF
tsc test.ts

Expected: compilation success Actual:

../node_modules/@deno/sham-weakref/dist/index.d.ts:2:14 - error TS1169: A computed property name in an interface must refer to an expression whose type is a literal type or a 'unique symbol' type.

2     readonly [Symbol.toStringTag]: "WeakRef";
               ~~~~~~~~~~~~~~~~~~~~

../node_modules/@deno/sham-weakref/dist/index.d.ts:2:15 - error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later.

2     readonly [Symbol.toStringTag]: "WeakRef";
                ~~~~~~

../node_modules/@sgwilym/isomorphic-streams/index.d.ts:2:3 - error TS1165: A computed property name in an ambient context must refer to an expression whose type is a literal type or a 'unique symbol' type.

2   [Symbol.asyncIterator](): AsyncIterator<R>;
    ~~~~~~~~~~~~~~~~~~~~~~

../node_modules/@sgwilym/isomorphic-streams/index.d.ts:2:4 - error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later.

2   [Symbol.asyncIterator](): AsyncIterator<R>;
     ~~~~~~

../node_modules/@sgwilym/isomorphic-streams/index.d.ts:2:29 - error TS2583: Cannot find name 'AsyncIterator'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.
[...]

This is with Version 5.4.5 of tsc.