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

Supply TypeScript typings #1

Closed
lucacasonato opened this issue Oct 21, 2020 · 6 comments
Closed

Supply TypeScript typings #1

lucacasonato opened this issue Oct 21, 2020 · 6 comments

Comments

@lucacasonato
Copy link

Deno will not automatically pick up on these, so the js files will need to include a type reference explicitly: https://deno.land/manual/getting_started/typescript#triple-slash-reference-directive-in-javascript-files

@oscarotero
Copy link
Collaborator

Yes, I tried to add the typings but it fails because some files, like this import types from external dependencies.

I'm getting this error:

import { RawSourceMap, SourceMapGenerator } from "./deps.js";
         ~~~~~~~~~~~~
    at file:///Users/oscarotero/www/postcss/postcss-deno/deno/lib/postcss.d.ts:1:10

TS2305 [ERROR]: Module '"./deps.js"' has no exported member 'SourceMapGenerator'.
import { RawSourceMap, SourceMapGenerator } from "./deps.js";
                       ~~~~~~~~~~~~~~~~~~
    at file:///Users/oscarotero/www/postcss/postcss-deno/deno/lib/postcss.d.ts:1:24

Found 2 errors.

I've tried to include these module members in the deps file (https://github.com/postcss/postcss-deno/blob/master/deps.js) (the file to manage all external dependencies), but this does not work:

export { default as mozilla, RawSourceMap, SourceMapGenerator } from "https://dev.jspm.io/source-map@0.6.1/source-map.js";

This may be cause some dependencies (like source-map) need to be loaded from jspm as long as there's no Deno version yet.

If you want to try, just need to set transpile: false in the conversion settings: https://github.com/postcss/postcss-deno/blob/master/to_deno.js#L8 and run the script run.sh. I'm not a TypeScript expert but maybe you can find a workaround.

@shadowtime2000
Copy link

@oscarotero You could try using Skypack with ?dts to send the Typescript header over.

@oscarotero
Copy link
Collaborator

@shadowtime2000 It looks like node modules are not replaced by deno alternatives:

Download https://cdn.skypack.dev/source-map?dts
Download https://cdn.skypack.dev/-/source-map@v0.7.3-sQuVq1KuD7hLWMINjPsN/dist=es2020/source-map.js
Download https://cdn.skypack.dev/-/source-map@v0.7.3-sQuVq1KuD7hLWMINjPsN/dist=es2020,mode=types/source-map.d.ts
Download https://cdn.skypack.dev/error/node:fs?from=source-map
error: Uncaught Error: [Package Error] "fs" does not exist. (Imported by "source-map").
throw new Error("[Package Error] \"fs\" does not exist. (Imported by \"source-map\").");
      ^
    at https://cdn.skypack.dev/error/node:fs?from=source-map:14:7

I've found this port https://github.com/denolib/deno-source-map but it gives some errors in the tests:

TypeError: MappingList is not a constructor
    at new SourceMapGenerator (https://raw.githubusercontent.com/denolib/deno-source-map/master/lib/source-map-generator.js:33:22)
    at MapGenerator.generateString (file:///Users/oscarotero/www/deno/postcss-deno/deno/lib/map-generator.js:209:16)
    at MapGenerator.generateMap (file:///Users/oscarotero/www/deno/postcss-deno/deno/lib/map-generator.js:163:10)
    at MapGenerator.generate (file:///Users/oscarotero/www/deno/postcss-deno/deno/lib/map-generator.js:277:19)
    at LazyResult.stringify (file:///Users/oscarotero/www/deno/postcss-deno/deno/lib/lazy-result.js:253:20)
    at LazyResult.get map (file:///Users/oscarotero/www/deno/postcss-deno/deno/lib/lazy-result.js:159:17)
    at file:///Users/oscarotero/www/deno/postcss-deno/deno/test/lazy-result.test.js:36:18
    at asyncOpSanitizer (deno:runtime/js/40_testing.js:36:13)
    at Object.resourceSanitizer [as fn] (deno:runtime/js/40_testing.js:70:13)
    at TestRunner.[Symbol.asyncIterator] (deno:runtime/js/40_testing.js:245:24)

generates result with map
TypeError: MappingList is not a constructor
    at new SourceMapGenerator (https://raw.githubusercontent.com/denolib/deno-source-map/master/lib/source-map-generator.js:33:22)
    at MapGenerator.generateString (file:///Users/oscarotero/www/deno/postcss-deno/deno/lib/map-generator.js:209:16)
    at MapGenerator.generateMap (file:///Users/oscarotero/www/deno/postcss-deno/deno/lib/map-generator.js:163:10)
    at MapGenerator.generate (file:///Users/oscarotero/www/deno/postcss-deno/deno/lib/map-generator.js:277:19)
    at LazyResult.stringify (file:///Users/oscarotero/www/deno/postcss-deno/deno/lib/lazy-result.js:253:20)
    at Root.toResult (file:///Users/oscarotero/www/deno/postcss-deno/deno/lib/root.js:44:17)
    at root.test.ts:52:21
    at asyncOpSanitizer (deno:runtime/js/40_testing.js:36:13)
    at Object.resourceSanitizer [as fn] (deno:runtime/js/40_testing.js:70:13)
    at TestRunner.[Symbol.asyncIterator] (deno:runtime/js/40_testing.js:245:24)

@shadowtime2000
Copy link

@oscarotero You could try using the @deno-types compiler hint with the type definitions from unpkg.

@oscarotero
Copy link
Collaborator

@shadowtime2000 I finally managed to maintain the types without errors and created a new branch typescript that you can use to test.

I have forked the deno-source-map repository and fixed the error. I've also created a pull request (denolib/deno-source-map#1) but using my own fork meanwhile.

@shadowtime2000 shadowtime2000 mentioned this issue Jan 13, 2021
Closed
@oscarotero
Copy link
Collaborator

Well, I think this issue is fixed. I added the TypeScript typings and everything works fine, so the next tagged version will supply the types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants