superstruct
superstruct copied to clipboard
make it available for Deno
Please make superstruct available for Deno also in Deno.land
No idea how to do this, but I'm open to someone setting it up.
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.
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.
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.
Missing .ts
in imports and exports which must be explicitly written
example:
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 the cdn.skypack.dev
does not include typescript types
@hemedani worked for me with no additional setup in vscode:
but it's not worked for me
Sorry, I could not get what I meant, I mean it does not include superstruct typescript utils like Infer
@hemedani hm, yes indeed, in this case I apologize for suggesting a method that doesn't quite work
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.
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.
it's worked fine till now