superstruct icon indicating copy to clipboard operation
superstruct copied to clipboard

make it available for Deno

Open hemedani opened this issue 4 years ago • 14 comments

Please make superstruct available for Deno also in Deno.land

hemedani avatar Oct 08 '20 09:10 hemedani

No idea how to do this, but I'm open to someone setting it up.

ianstormtaylor avatar Nov 19 '20 21:11 ianstormtaylor

Hi! I'm trying to use superstruct on Deno and have some input on this:

Currently, superstruct is present in Deno.land -> https://deno.land/x/superstruct. deno.land is just a cache that points to Git repositories containing modules for Deno. In Deno dependencies are not managed by some npm-like package manager. Modules are just HTTPS addresses pointing to code.

superstruct in deno.land is pointing to this repository's src folder, but currently it doesn't work. First reason is: imports doesn't include the .ts file extension, which is required in Deno.

Also I'm having some issues like these, but that's what I'm currently working on.

error: TS7053 [ERROR]: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type '{}'.
  Property '[SymbolConstructor.iterator]' does not exist on type '{}'.
  return isObject(x) && typeof x[Symbol.iterator] === 'function'
                               ~~~~~~~~~~~~~~~~~~
    at file:///home/sirikon/repos/srkbz-genesis/src/kubernetes/defgen/src/vendor/superstruct/utils.ts:9:32

TS7053 [ERROR]: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
  No index signature with a parameter of type 'string' was found on type '{}'.
        if (struct.schema[key] === undefined) {
            ~~~~~~~~~~~~~~~~~~
    at file:///home/sirikon/repos/srkbz-genesis/src/kubernetes/defgen/src/vendor/superstruct/utils.ts:142:13

TS7053 [ERROR]: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
  No index signature with a parameter of type 'string' was found on type '{}'.
          delete value[key]
                 ~~~~~~~~~~
    at file:///home/sirikon/repos/srkbz-genesis/src/kubernetes/defgen/src/vendor/superstruct/utils.ts:143:18

TS7053 [ERROR]: Element implicitly has an 'any' type because expression of type 'string | number' can't be used to index type '{}'.
  No index signature with a parameter of type 'string' was found on type '{}'.
          value[k] = v
          ~~~~~~~~
    at file:///home/sirikon/repos/srkbz-genesis/src/kubernetes/defgen/src/vendor/superstruct/utils.ts:178:11

TS7053 [ERROR]: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
  No index signature with a parameter of type 'string' was found on type '{}'.
          yield [key, value[key], schema[key]]
                      ~~~~~~~~~~
    at file:///home/sirikon/repos/srkbz-genesis/src/kubernetes/defgen/src/vendor/superstruct/structs/types.ts:345:23

TS7053 [ERROR]: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
  No index signature with a parameter of type 'string' was found on type '{}'.
          yield [key, value[key], Never]
                      ~~~~~~~~~~
    at file:///home/sirikon/repos/srkbz-genesis/src/kubernetes/defgen/src/vendor/superstruct/structs/types.ts:349:23

TS7053 [ERROR]: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
  No index signature with a parameter of type 'string' was found on type '{}'.
          const v = value[k]
                    ~~~~~~~~
    at file:///home/sirikon/repos/srkbz-genesis/src/kubernetes/defgen/src/vendor/superstruct/structs/types.ts:394:21

TS7053 [ERROR]: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
  No index signature with a parameter of type 'string' was found on type '{}'.
          yield [k, value[k], schema[k]]
                    ~~~~~~~~
    at file:///home/sirikon/repos/srkbz-genesis/src/kubernetes/defgen/src/vendor/superstruct/structs/types.ts:557:21

Found 8 errors.

sirikon avatar Jul 22 '21 17:07 sirikon

Update on that: Seems like doing this in every place where it gets an error does the trick, but probably not the best solution. Good enough for my local fork unless it breaks somewhere.

image

sirikon avatar Jul 22 '21 17:07 sirikon

After more testing, I think it works pretty well with the changes mentioned before. Have been using it for a Deno-based project yesterday and worked well.

Fixing the issues so Deno users can use it from deno.land should be straightforward, but making the unit tests work on Deno might require more work.

sirikon avatar Jul 23 '21 10:07 sirikon

Missing .ts in imports and exports which must be explicitly written

example: image

roonie007 avatar Jan 01 '22 02:01 roonie007

Also note to deno users: you can use this module via ES module CDNs, e.g.:

import * as ss from "https://cdn.skypack.dev/[email protected]";

const User = ss.object({
  name: ss.string(),
  age: ss.number(),
});

console.log(ss.validate({name: "john", age: 19}, User));
console.log(ss.validate({name: "john"}, User));


nsf avatar Mar 24 '22 04:03 nsf

@nsf the cdn.skypack.dev does not include typescript types

hemedani avatar Mar 26 '22 08:03 hemedani

@hemedani worked for me with no additional setup in vscode: image

nsf avatar Mar 26 '22 08:03 nsf

but it's not worked for me Screen Shot 1401-01-06 at 13 38 56

hemedani avatar Mar 26 '22 09:03 hemedani

Sorry, I could not get what I meant, I mean it does not include superstruct typescript utils like Infer

hemedani avatar Mar 26 '22 09:03 hemedani

@hemedani hm, yes indeed, in this case I apologize for suggesting a method that doesn't quite work

nsf avatar Mar 26 '22 09:03 nsf

https://esm.sh/ Works if you need types, they explicitly have Deno support.

Anyone using these random CDNs from the internet, consider using Deno’s locking mechanism to ensure that the dependencies doesn’t change from time to time.

sirikon avatar Mar 26 '22 10:03 sirikon

I'm just creating a clone version of this on deno.land : https://deno.land/x/lestruct

it just changes a little folder structure and adds some any type for eliminates several errors.

in the future maybe I add some additional structure, especially to long files, and add documentation also.

hemedani avatar Mar 26 '22 11:03 hemedani

it's worked fine till now

hemedani avatar Mar 26 '22 11:03 hemedani