utility-types icon indicating copy to clipboard operation
utility-types copied to clipboard

docs: how to use utility-types in deno

Open FaberVitale opened this issue 5 years ago • 6 comments

Is your feature request related to a real problem or use-case?

It is not currently possible to import/run utility-types in deno due to different way node and deno resolve imports (aka module resolution).

deno run 'https://raw.githubusercontent.com/piotrwitek/utility-types/master/src/index.ts'
Download https://raw.githubusercontent.com/piotrwitek/utility-types/master/src/index.ts
Download https://raw.githubusercontent.com/piotrwitek/utility-types/master/src/utility-types
Download https://raw.githubusercontent.com/piotrwitek/utility-types/master/src/mapped-types
Download https://raw.githubusercontent.com/piotrwitek/utility-types/master/src/aliases-and-guards
Download https://raw.githubusercontent.com/piotrwitek/utility-types/master/src/functional-helpers
error: Import 'https://raw.githubusercontent.com/piotrwitek/utility-types/master/src/utility-types' failed: 404 Not Found

Describe a solution including usage in code example

2 Suggested solutions

  • Use a compiler like denoify to emit a compiled output that deno understands.

  • Refactor: remove all imports.

Who does this impact? Who is this for?

deno users.

Describe alternatives you've considered (optional)

Additional context (optional)

  • https://deno.land/manual

  • https://github.com/garronej/denoify

  • https://deno.land/manual/getting_started/typescript

  • https://www.typescriptlang.org/docs/handbook/module-resolution.html

2023-02-20 Update

https://github.com/piotrwitek/utility-types/issues/141#issuecomment-1437364398

FaberVitale avatar May 31 '20 10:05 FaberVitale

Hey @FaberVitale 

Thanks for creating PR. I'll take a look ASAP and come back to you.

piotrwitek avatar Jun 01 '20 09:06 piotrwitek

up

mcandeia avatar Feb 18 '23 11:02 mcandeia

I'm not familiar with Deno and would like to use some help here. @mcandeia are you able to review and test existing PR to see if that's working as expected and will not break anything for existing nodejs users?

piotrwitek avatar Feb 20 '23 10:02 piotrwitek

I developed this PR 3 years ago.

It's possible that these changes are obsolete: It's now possible to import node packages in deno:

https://deno.land/[email protected]/node

FaberVitale avatar Feb 20 '23 11:02 FaberVitale

It works!

I've just tested it using the following test file:

// deno_test.ts
import * as utilityTypes from 'npm:[email protected]'

console.log('\nutility-types module', utilityTypes)
console.log('\nisPrimitive', utilityTypes.isPrimitive({}), utilityTypes.isPrimitive(2))
$ deno run deno_test.ts  


utility-types module Module {
  __esModule: true,
  default: {
    isFalsy: [Function],
    isPrimitive: [Function],
    getReturnOfExpression: [Function: getReturnOfExpression]
  },
  getReturnOfExpression: [Function: getReturnOfExpression],
  isFalsy: [Function],
  isPrimitive: [Function]
}

isPrimitive false true

deno --version
deno 1.30.3 (release, x86_64-apple-darwin)
v8 10.9.194.5
typescript 4.9.4

@piotrwitek you probably just need to add deno specific tests and document how to run the library in deno.

FaberVitale avatar Feb 20 '23 17:02 FaberVitale

Thanks a lot for your help @FaberVitale!

piotrwitek avatar Feb 21 '23 11:02 piotrwitek