Given an import map that maps "utils/" to "./src/utils/", what will be the resolved path when importing "utils/helpers.ts"?
import helpers from "utils/helpers.ts";
Think about how the import map replaces the prefix in the import path.
The import map replaces the prefix "utils/" with "./src/utils/", so "utils/helpers.ts" becomes "./src/utils/helpers.ts".
Choose the correctly structured import map JSON for mapping "lib/" to "./libraries/".
Check the exact key name and value types required by Deno's import map spec.
Deno requires the key "imports" with an object mapping prefixes to paths. Option B matches this exactly.
Given this import map:
{ "imports": { "components/": "./src/components/" } }And this import statement:
import Button from "component/Button.ts";
Why does the import fail?
import Button from "component/Button.ts";
Check the exact spelling and trailing slashes in the import path and map keys.
The import map key is "components/" but the import uses "component/" (missing 's'). Import maps require exact prefix matches including trailing slashes.
Given the import map:
{ "imports": { "utils/": "./lib/utils/" } }And the file structure:
./lib/utils/math.tsexportsexport const add = (a, b) => a + b;
And this script:
import { add } from "utils/math.ts";
console.log(add(2, 3));What will be printed when running this script with the import map?
import { add } from "utils/math.ts"; console.log(add(2, 3));
Consider how the import map resolves the path and what the add function returns.
The import map resolves "utils/math.ts" to "./lib/utils/math.ts" which exports add correctly. Calling add(2, 3) returns 5.
Choose the best explanation of why import maps improve Deno project development.
Think about how import maps affect the way you write import paths.
Import maps let you create aliases for long or nested paths, making imports shorter and easier to read. They do not minify, enforce typing, or eliminate all path types.
