TypeScript Versions:  3.5.3 and 3.7.0-dev.20190820
Search Terms:
typescript paths remain after compile in type definition files
Code
index.ts
export * from '~/b'
b.ts
export const myThing = 'Something'
tsconfig.json
{
  "compilerOptions": {
    "target": "esnext",
    "module": "es2015",
    "declaration": true,
    "outDir": "dist",
    "strict": true,
    "moduleResolution": "node",
    "baseUrl": "./",
    "paths": {
      "~/*": ["src/*"]
    }
  }
}
Expected behavior:
/dist/index.d.ts
export * from './b'
Actual behavior:
/dist/index.d.ts
export * from '~/b'
More Info:
My package.json has
{
    "main": "dist/index.js",
     "types": "dist/index.d.ts",
}
When someone imports the package, the types are broken because the paths don't resolve to the expected files.
Perhaps I am approaching this incorrectly. Is there an alternative method to deal with path resolution?
This is the intended behavior. TypeScript's golden rule about import paths is never change what the user wrote; this applies both to .d.ts and .js outputs. This is the most predictable behavior and the most controllable from the dev side.
How you want to fix this really depends on why you wrote it as ~/b in the first place.
never change what the user wrote
As an aside: While I agree with this approach on the whole, it is a problem specifically for file extensions: TS understands extensionless imports, but not all environments do.  e.g. I believe Deno requires an extension, as do browsers, and there's no way to deal with this discrepancy on the TS side--paths doesn't help here.  (TS does understand imports ending in .js, but not e.g. .mjs--and auto-import always omits the extension).
How you want to fix this really depends on why you wrote it as ~/b in the first place.
A nice default I use for projects is set ~ as the src directory, allowing for the use of absolute imports.
import env from ~/environment`
vs
import env from '../../../environment'
When using absolute paths in a library which is intended to be hosted in npm, the absolute paths no longer register as the application is compiled into a different folder.
Should I set my tsconfig.compilerOptions.path to { "~/*": ["./src/*", "./dist/*" ]  
You shouldn't use paths at all in that case - paths exists to instruct the compiler how the runtime is expected to interpret paths, not to dictate to TS how to rewrite them so they work at runtime.
Oh. So what is the intended use case for paths?
paths is for when you have module paths that are already resolvable at runtime, but TS doesn鈥檛 understand them, so you can point the compiler to where it can find them.
It鈥檚 not an aliasing feature, sadly.
That's a bummer. Does the TS team have any plans to introduce an tsconfig.compilerOptions.aliases feature?
Most likely not: https://github.com/microsoft/TypeScript/issues/31643#issuecomment-496995677
For the record, your use case--sometimes wanting to use a rooted path instead of multiple levels of ../--is why I support the path form @/absolute/path at runtime in miniSphere.  I wish it were possible to do the same in Node.js (rooted at the location of package.json, for example) but unfortunately it isn't 馃檨 
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
Thumb up if you used baseUrl and rootDirs now you are here :)
Most helpful comment
Thumb up if you used
baseUrlandrootDirsnow you are here :)