101arrowz / fzstd

High performance Zstandard decompression in a pure JavaScript, 8kB package
MIT License
218 stars 11 forks source link

Deno bundle fails #2

Closed mcraiha closed 2 years ago

mcraiha commented 3 years ago

Hi, I was planning to add some deno test cases for this project, but it seems deno bundle fails with following errors

error: TS2345 [ERROR]: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. Type 'undefined' is not assignable to type 'number'. if (u8.prototype.copyWithin) return u8.prototype.copyWithin.call(v, t, s, e); ^ at fzstd/src/index.ts:68:74

TS2366 [ERROR]: Function lacks ending return statement and return type does not include 'undefined'. const rzfh = (dat: Uint8Array, w?: Uint8Array | 1): number | DZstdState => {

at fzstd/src/index.ts:127:53

TS2365 [ERROR]: Operator '+' cannot be applied to types 'number' and 'number | boolean'.
const fss = rb(dat, bt, fsb) + ((fcf == 1) && 256);

at fzstd/src/index.ts:145:17

TS2345 [ERROR]: Argument of type 'HDT | undefined' is not assignable to parameter of type 'HDT'. Type 'undefined' is not assignable to type 'HDT'. (s4 ? dhu4 : dhu)(dat.subarray(bt, bt += lcs), buf.subarray(spl), hu); ~~ at fzstd/src/index.ts:497:73

TS2532 [ERROR]: Object is possibly 'undefined'. dts[i] = st.t[i];

at fzstd/src/index.ts:524:20

TS2322 [ERROR]: Type 'null' is not assignable to type 'Uint8Array | undefined'.
buf = null;

at fzstd/src/index.ts:641:9

TS2345 [ERROR]: Argument of type 'Uint8Array | undefined' is not assignable to parameter of type 'Uint8Array'. Type 'undefined' is not assignable to type 'Uint8Array'. bufs.push(buf);

at fzstd/src/index.ts:647:19

TS2345 [ERROR]: Argument of type 'Uint8Array | undefined' is not assignable to parameter of type 'Uint8Array'.
Type 'undefined' is not assignable to type 'Uint8Array'.
bufs.push(blk);

at fzstd/src/index.ts:655:21

TS2532 [ERROR]: Object is possibly 'undefined'. ol += blk.length;

at fzstd/src/index.ts:656:17

TS2532 [ERROR]: Object is possibly 'undefined'.
cpw(st.w, 0, blk.length);

at fzstd/src/index.ts:657:24

TS2345 [ERROR]: Argument of type 'Uint8Array | undefined' is not assignable to parameter of type 'ArrayLike'. Type 'undefined' is not assignable to type 'ArrayLike'. st.w.set(blk, st.w.length - blk.length);

at fzstd/src/index.ts:658:20

TS2532 [ERROR]: Object is possibly 'undefined'.
st.w.set(blk, st.w.length - blk.length);

at fzstd/src/index.ts:658:39

TS2564 [ERROR]: Property 's' has no initializer and is not definitely assigned in the constructor. private s: DZstdState | number; ^ at fzstd/src/index.ts:679:11

TS2322 [ERROR]: Type 'ZstdStreamHandler | undefined' is not assignable to type 'ZstdStreamHandler'. Type 'undefined' is not assignable to type 'ZstdStreamHandler'. this.ondata = ondata; at fzstd/src/index.ts:688:5

TS7023 [ERROR]: 'push' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. push(chunk: Uint8Array, final?: boolean) { at fzstd/src/index.ts:699:3

101arrowz commented 3 years ago

You probably don't want to use the actual TypeScript source (it's written in loose mode TS, which is nice for DX but doesn't have the same requirements as strict TS, which Deno uses). Instead you should use the JavaScript with the TypeScript typings file.

// Don't use the ?dts Skypack flag; it isn't necessary for Deno support
// The @deno-types comment adds TypeScript typings

// @deno-types="https://cdn.skypack.dev/fflate/lib/index.d.ts"
import * as fflate from 'https://cdn.skypack.dev/fflate?min';

Let me know if that works.

mcraiha commented 3 years ago

Hi,

I can already run tests with --no-check flag. It is just that I could also easily test .ts validity with Deno. Do you want a pull request from following commit? And another one for GitHub actions to test them automatically? https://github.com/mcraiha/fzstd/commit/a6af12401e8f445fa7abc7294bad3564a4c9381b

101arrowz commented 2 years ago

Sorry I completely missed this, please feel free to create the PR with tests. GH actions aren't necessary if they're not set up already - I usually don't use them.

From your reply I think --no-check is acceptable for Deno users who want to use the full TS version, so I'm closing for now. TSC does the "testing" of the validity of the types when building so I don't think that part is really necessary.