Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deno support? #97

Closed
andykais opened this issue Sep 30, 2021 · 14 comments · Fixed by #100
Closed

deno support? #97

andykais opened this issue Sep 30, 2021 · 14 comments · Fixed by #100
Assignees
Labels
help wanted Extra attention is needed

Comments

@andykais
Copy link

is it possible to use this module inside deno? Skypack imports dont seem to work

import * as helpers from 'https://cdn.skypack.dev/ts-helpers'
// helpers is empty

and importing the source from github isnt an option either because paths arent fully resolved

import {exactly} from 'https://raw.githubusercontent.com/DetachHead/ts-helpers/master/src/utilityFunctions/misc.ts'
// error: Import 'https://raw.githubusercontent.com/DetachHead/ts-helpers/master/src/utilityFunctions/Any' failed: 404 Not Found
@KotlinIsland
Copy link
Collaborator

KotlinIsland commented Oct 1, 2021

Deno is based 100 so I intent to add full support. I'm embarrassed that we don't have support already.

@KotlinIsland
Copy link
Collaborator

Have you tried esm.sh?

@andykais
Copy link
Author

andykais commented Oct 1, 2021

no good

> import * as ts_helpers from 'https://esm.sh/ts-helpers'
undefined
> ts_helpers
Module { default: null }

@DetachHead
Copy link
Owner

@andykais might be because there's no index.ts anymore. I removed it because of conflicting names between functions/types between files that was becoming too difficult to work around (eg. Both Array and String have a Head type). If you have a better solution in mind I'm all ears. Cus I don't like how it is now

This means you have to import from individual files directly, so your second example in the OP should work with esm.sh. Let me know if it doesn't

@andykais
Copy link
Author

andykais commented Oct 4, 2021

what you are saying makes sense but I dont know what the paths are on esm.sh. Is it src/utilityFunctions/Array.ts or are they built .js files? Can you share an example path?

@DetachHead
Copy link
Owner

the npm package has built .js and .d.ts files in the dist directory, however with deno you should be able to just import from src, for example:

import {exactly} from 'http://esm.sh/@detachhead/ts-helpers/src/utilityFunctions/misc.ts'

@andykais
Copy link
Author

andykais commented Oct 6, 2021

no such luck:

Download http://esm.sh/@detachhead/ts-helpers/src/utilityFunctions/misc.ts
Download http://esm.sh/@detachhead/[email protected]/src/utilityFunctions/misc.ts
Download http://esm.sh/@detachhead/[email protected]/src/utilityTypes/String
Download http://esm.sh/@detachhead/[email protected]/src/utilityTypes/misc
Download http://esm.sh/@detachhead/[email protected]/src/utilityFunctions/Any
Download http://esm.sh/@detachhead/[email protected]/src/utilityTypes/String
error: Import 'http://esm.sh/@detachhead/[email protected]/src/utilityTypes/misc' failed: 500 Internal Server Error
    at http://esm.sh/@detachhead/[email protected]/src/utilityFunctions/misc.ts:2:0

retrying gives 500 at different imports

error: Import 'http://esm.sh/@detachhead/[email protected]/src/utilityFunctions/Any' failed: 500 Internal Server Error
    at http://esm.sh/@detachhead/[email protected]/src/utilityFunctions/misc.ts:4:0

@DetachHead
Copy link
Owner

i'm not sure then sorry. unfortunately i've experienced lots of issues running & debuging with deno on my machines which is why i've stuck with node. if you or anyone else figures out how to get it working i'd happily accept a PR.

it may be something that fixes itself with #76, who knows

@DetachHead DetachHead added the help wanted Extra attention is needed label Oct 9, 2021
@KotlinIsland
Copy link
Collaborator

KotlinIsland commented Oct 9, 2021

So the actual import is

import { exactly } from 'http://esm.sh/@detachhead/ts-helpers/dist/utilityFunctions/misc'

but ts-ignore comments aren't included in the d.ts so it's basically useless 😕.

@KotlinIsland
Copy link
Collaborator

I'm going to try and add deno support.

@KotlinIsland KotlinIsland self-assigned this Oct 10, 2021
@DetachHead DetachHead mentioned this issue Oct 12, 2021
@DetachHead
Copy link
Owner

i've removed all of the //@ts-expect-error comments that were getting exposed in the .d.ts files as well as cleaned up a bunch of other stuff #100

can you try importing this version from esm.sh and let me know if it works?

import { exactly } from 'http://esm.sh/@detachhead/[email protected]/dist/utilityFunctions/misc'

@andykais
Copy link
Author

It works! The following snippet seems to do error on everything I throw at it

import { exactly } from 'http://esm.sh/@detachhead/[email protected]/dist/utilityFunctions/misc'
import * as z from 'https://deno.land/x/[email protected]/mod.ts'


interface Foo {
  bar: string
  baz?: string // removing this line gives an error
  bot: 'a' | 'b'
}

const FooValidator = z.object({
  bar: z.string(),
  baz: z.string().optional(), // removing this line gives the error
  bot: z.union([z.literal('a'), z.literal('b')]), // adding/removing a literal from the union gives the error
})

exactly({} as z.input<typeof FooValidator>, {} as Foo)

//values (also does a runtime assertion on the values)

Is this opt-out though? These are definitely not two runtime equivalent values

would you plan to publish to the deno repository (https://deno.land/x)?

@DetachHead
Copy link
Owner

if you only want to test the types, you can do it like this:

exactly<z.input<typeof FooValidator>, Foo>()

or if you're checking a value against a type:

exactly<z.input<typeof FooValidator>>()({} as Foo)

as for the type errors, those are happening because exactly is doing an exact match on the types (ie. that the types are structurally exactly the same, not that one extends the other). if you want to just check that one extends the other, you can use

assertType<z.input<typeof FooValidator>>({} as Foo)

that way, you'll no longer get errors when removing those properties from Foo and FooValidator

would you plan to publish to the deno repository (https://deno.land/x)?

i'll leave that up to @KotlinIsland, i'm not much of a deno user so what are the benefits of publishing there over using esm.sh?

@andykais
Copy link
Author

that way, you'll no longer get errors when removing those properties from Foo and FooValidator

oh actually I do want those errors! I was just pointing out that exactly seems to properly find all differences in those comments. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants