It has finally become available in Typescript 4.7
Your library:
// package.json
"exports": {
".": "./dist/index.js",
"./svg": "./dist/svg.js",
"./html": "./dist/html.js",
"./package.json": "./package.json"
},
Your client code must have:
// tsconfig.json
"compilerOptions": {
"moduleResolution": "node16" // or "nodenext"
}
Prior to Typescript 4.7 you could utilize typesVersions:
// package.json
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": "./dist/index.js",
"./svg": "./dist/svg.js",
"./html": "./dist/html.js",
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"svg": ["dist/svg.d.ts"],
"html": ["dist/html.d.ts"]
}
}