Skip to content

Consider redesigning "resolution-mode" to not be an assertion since it's not an assertion #48644

Closed
@dsherret

Description

@dsherret

Suggestion

The latest TS 4.7 has a new "resolution-mode" feature (https://devblogs.microsoft.com/typescript/announcing-typescript-4-7-beta/#resolution-mode) that can be used to select which module resolution to use:

import type { TypeFromRequire } from "pkg" assert {
    "resolution-mode": "require" // or "import"
};

I understand this is "ok" by the spec police because it appears in an import type, but this is not an assertion so it appearing in an assert clause doesn't seem ideal.

Note: I say this is not an assertion because import assertions assert something about the module. This instead seems to be a module resolution directive... maybe I'm mistaken though.

🔍 Search Terms

resolution-mode import assertions

⭐ Suggestion

I think @nayeemrmn's suggestion for using a comment directive seems more ideal #47807 (comment):

// @ts-resolution="require"
import type { RequireInterface } from "pkg";

...but that's not as conveinent when used in a type like shown in the example:

export type LocalType =
    & import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface
    & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface;

Perhaps this should be?

export type LocalType =
    & require("pkg").RequireInterface
    & import("pkg").ImportInterface;

Or, perhaps still using a comment directive:

export type LocalType =
    & /* @ts-resolution="require" */ import("pkg").RequireInterface
    & import("pkg").ImportInterface;

Metadata

Metadata

Labels

In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions