cf.completefrontend

Predict the typesHard

Under module: nodenext, which of these imports does TypeScript reject, and why write .js for a .ts file?

The project is compiled by tsc and run by Node.js. Its package.json has "type": "module", and its tsconfig sets module: "nodenext". Name every error TypeScript reports in src/main.ts.

package.json
{ "name": "shop-server", "type": "module" }
src/format.ts
export function formatPrice(cents: number) {
  return "$" + (cents / 100).toFixed(2);
}
src/config/index.ts
export const currency = "USD";
What does TypeScript report here? (src/main.ts)
import { formatPrice } from "./format";import { formatPrice as format } from "./format.js";import { formatPrice as price } from "./format.ts";import { currency } from "./config";import { currency as code } from "./config/index.js"; console.log(format(1999), code);

Compiler options: module: "nodenext", moduleResolution: "nodenext", allowImportingTsExtensions: false

Work it out first: the compiler shows every error and type.

The answer

Work out every error TypeScript reports and every type it shows, line by line. Then check.

Checking your sign-in…