Skip to content

Commit d404386

Browse files
docs: Fixed root import name for typeVersions (#10180)
should be index.d.ts, not index Co-authored-by: Willow (GHOST) <[email protected]> --------- Co-authored-by: Willow (GHOST) <[email protected]>
1 parent d66d316 commit d404386

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

.changeset/tiny-insects-repeat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte-migrate': patch
3+
---
4+
5+
fix: changed `index` to `index.d.ts` in `typesVersions`

documentation/docs/30-advanced/70-packaging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ The second option is to (ab)use the `typesVersions` feature from TypeScript to w
152152
}
153153
```
154154

155-
`>4.0` tells TypeScript to check the inner map if the used TypeScript version is greater than 4 (which should in practice always be true). The inner map tells TypeScript that the typings for `your-library/foo` are found within `./dist/foo.d.ts`, which essentially replicates the `exports` condition. You also have `*` as a wildcard at your disposal to make many type definitions at once available without repeating yourself. Note that if you opt into `typesVersions` you have to declare all type imports through it, including the root import (which is defined as `"index": [..]`).
155+
`>4.0` tells TypeScript to check the inner map if the used TypeScript version is greater than 4 (which should in practice always be true). The inner map tells TypeScript that the typings for `your-library/foo` are found within `./dist/foo.d.ts`, which essentially replicates the `exports` condition. You also have `*` as a wildcard at your disposal to make many type definitions at once available without repeating yourself. Note that if you opt into `typesVersions` you have to declare all type imports through it, including the root import (which is defined as `"index.d.ts": [..]`).
156156

157157
You can read more about that feature [here](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#version-selection-with-typesversions).
158158

packages/migrate/migrations/package/migrate_pkg.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function update_pkg_json(config, pkg, files) {
114114
}`;
115115

116116
if (has_type) {
117-
const type_key = key.slice(2) || 'index';
117+
const type_key = key.slice(2) || 'index.d.ts';
118118
if (!pkg.exports[key]) {
119119
types_versions[type_key] = [out_dir_type_path];
120120
} else {
@@ -191,7 +191,7 @@ export function update_pkg_json(config, pkg, files) {
191191
// A hack to get around the limitation that TS doesn't support "exports" field with moduleResolution: 'node'
192192
if (
193193
Object.keys(types_versions).length > 1 ||
194-
(Object.keys(types_versions).length > 0 && !types_versions['index'])
194+
(Object.keys(types_versions).length > 0 && !types_versions['index.d.ts'])
195195
) {
196196
pkg.typesVersions = { '>4.0': types_versions };
197197
}

packages/migrate/migrations/package/migrate_pkg.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ test('Updates package.json', () => {
9494
svelte: './package/index.js',
9595
typesVersions: {
9696
'>4.0': {
97-
index: ['./package/index.d.ts'],
97+
'index.d.ts': ['./package/index.d.ts'],
9898
'foo/Bar.svelte': ['./package/foo/Bar.svelte.d.ts'],
9999
baz: ['./package/baz.d.ts'],
100100
bar: ['./package/bar/index.d.ts'],

0 commit comments

Comments
 (0)