Skip to content

Content mapper: Relative import does not fall back to type definition file when original file not in include arrayΒ #65697

Backlog

Description

@dummdidumm

πŸ”Ž Search Terms

content mapper include

πŸ•— Version & Regression Information

All TS 7.1 beta/nightly versions, not a regression but a bug

⏯ Playground Link

https://github.com/dummdidumm/ts-content-mapper-repro

πŸ’» Code

See below

πŸ™ Actual behavior

With #65047 merged I thought that we could use the include feature so that in node modules TypeScript would not resolve .svelte files and instead fall back to its normal module resolution, which means that type definition files are loaded.

E.g. when you have this package

node_modules/my-package/
  index.js
  index.d.ts
  Foo.svelte
  Foo.d.svelte.ts (or even Foo.svelte.d.ts)

with index.d.ts being

export { default as Foo } from './Foo.svelte';

and then a content mapper definition which contains include: ['./src/**'] (i.e. the content mapper is not used for packages in node_modules)
that it would then load the type definition Foo.d.svelte.ts (or even Foo.svelte.d.ts) from index.d.ts.

But this is not the case - it does result in a resolution error:
Could not find a declaration file for module './Foo.svelte'. '/.../node_modules/my-package/Foo.svelte' implicitly has an 'any' type.
and
File '/.../node_modules/my-package/Foo.svelte' has a registered content mapper extension but does not match any content mapper's 'include'.
both originating inside node_modules/my-package/index.d.ts (which does the relative import of Foo.svelte)
No difference whether or I turn on allowArbitraryExtensions or not.

No idea how to show this in the TypeScript playground so I linked a Github repo instead.

πŸ™‚ Expected behavior

"turning off" the content mapper for specific parts of the app should mean that module resolution works as if there is no content mapper at all defined in those places, i.e. it will use its normal module resolution, and see "oh there's a type definition file I'll load that".

Additional information about the issue

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions