Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change tsconfig/json moduleResolution to bundler #9007

Closed
ConProgramming opened this issue Feb 11, 2023 · 3 comments
Closed

Change tsconfig/json moduleResolution to bundler #9007

ConProgramming opened this issue Feb 11, 2023 · 3 comments

Comments

@ConProgramming
Copy link
Contributor

Describe the problem

To reiterate this issue: In TypeScript 4.7, along the property "module": "node16" that enables ESM features in TypeScript, there are new values for the property "moduleResolution": "node16" and "nodenext". Both values allows importing from dependencies with package.json exports, imports, and self-referencing.

Right now, this property in the default .sveltekit/tsconfig.json is "node." This doesn't support features like defining "types" in "exports".

Describe the proposed solution

Change tsconfig/json moduleResolution to node16 or nodenext. This will mean that relative import paths need explicit file extensions - so './$types.js'; instead of './$types';, and similar changes. It'd be a breaking change, atleast for typescript linting, but seems to be more future proof.

Alternatives considered

Keep moduleResolution as node. It's less future proof, as we'll keep having to use declare module and a global types property in package.json.

Importance

nice to have

Additional Information

No response

@david-plugge
Copy link
Contributor

Agree!

But in case you really need this today make use of typesVersions

{
	"exports": {
		".": {
			"types": "./dist/index.d.ts",
			"default": "./dist/index.js"
		},
		"./component": {
			"types": "./dist/component.d.ts",
			"default": "./dist/component.js"
		}
	},
	"types": "./dist/index.d.ts",
	"typesVersions": {
        "*": {
            "component": [
                "dist/component.d.ts"
            ]
        }
	}
}

https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#version-selection-with-typesversions

@ydcjeff
Copy link
Contributor

ydcjeff commented Feb 13, 2023

With moduleResolution nodenext, what would we use instead of declare module?

@dummdidumm
Copy link
Member

We won't be changing moduleResolution to next/node16 because it has lots of unpleasant side effects:

  • all relative imports now need the full path and file extension (and it's weird because you need to import TS files with a .js ending)
  • not properly built packages will suffer because their types are no longer resolved

Instead we should leverage TypeScript 5.0's upcoming moduleResolution: "bundler".

Changing this is a breaking change though (at least for create-svelte)

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

No branches or pull requests

5 participants