cannot find name with typescript and deno

Viewed 779

Here is my code :

/**
 * map.ts
 */


// @deno-types="./libs/@types/geojson/index.d.ts"
// @deno-types="./libs/@types/mapbox-gl/index.d.ts"

mapboxgl.accessToken =  "toto";

var map = new mapboxgl.Map({
  container: 'map', // container id
  style: 'mapbox://styles/mapbox/streets-v11', // style URL
  center: [-74.5, 40], // starting position [lng, lat]
  zoom: 9 // starting zoom
  });

But even if i have imported the definition of mapbox with

// @deno-types="./libs/@types/geojson/index.d.ts"
// @deno-types="./libs/@types/mapbox-gl/index.d.ts"

I have the error :

error: TS2304 [ERROR]: Cannot find name 'mapboxgl'.
mapboxgl.accessToken =  "toto";
~~~~~~~~
    at file:///home/bussiere/Workspace/testdeno2/map.ts:9:1

TS2304 [ERROR]: Cannot find name 'mapboxgl'.
var map = new mapboxgl.Map({
              ~~~~~~~~
    at file:///home/bussiere/Workspace/testdeno2/map.ts:11:15

Found 2 errors.

How to import correctly the definition in a way that i could be able to use the name and the definitions.

here is the github : https://github.com/bussiere/testdeno2

Edit :

here is the uncaught error :

error: Uncaught (in promise) RuntimeError: unreachable
    at <anonymous> (wasm://wasm/00247702:1:336403)
    at <anonymous> (wasm://wasm/00247702:1:341096)
    at <anonymous> (wasm://wasm/00247702:1:339419)
    at <anonymous> (wasm://wasm/00247702:1:339781)
    at <anonymous> (wasm://wasm/00247702:1:336272)
    at <anonymous> (wasm://wasm/00247702:1:268321)
    at minify (wasm://wasm/00247702:1:253183)
    at minify (https://deno.land/x/minifier@v1.1.1/wasm.js:98:14)
    at minify (https://deno.land/x/minifier@v1.1.1/mod.ts:27:10)
    at https://deno.land/x/minifier@v1.1.1/cli.ts:53:3

Regards

1 Answers

There is no reference of the library and I think you can install the package from skypack or pika to upgrade and downgrade easily instead of copying the lib to your repo.

Cache the 3rd party library by running deno info

deno info "https://cdn.skypack.dev/@types/mapbox-gl"
or 
deno info "https://cdn.pika.dev/mapbox-gl@^2.2.0" 

Import the mapbox-gl with type definition

// @deno-types="./libs/@types/mapbox-gl/index.d.ts"
import mapboxgl from "https://cdn.skypack.dev/mapbox-gl";
// or import mapboxgl from "https://cdn.pika.dev/mapbox-gl@^2.2.0";

mapboxgl.accessToken = "toto";

const map = new mapboxgl.Map({
  container: "map", // container id
  style: "mapbox://styles/mapbox/streets-v11", // style URL
  center: [-74.5, 40], // starting position [lng, lat]
  zoom: 9, // starting zoom
});

Related