microsoft / microsoft/TypeScript
Export an interface for JSON `CompilerOptions`
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Search Terms
- CompilerOptions
- convertCompilerOptionsFromJson
Suggestion
Currently TypeScript exports the CompilerOptions interface, which represents the compiler options that can be passed in. However, since this interface uses enums, it doesn't match with the format of compilerOptions in the tsconfig.json file. I'd like to be able to use a JsonCompilerOptions (or some better name) interface to strictly type options in libraries that wrap TypeScript without rewriting the interface.
Use Cases
- Libraries that wrap TypeScript like rollup-plugin-typescript can strictly type overrides for values in
tsconfigwithout either requiring the user to import TypeScript enums or rewriting the interface. - The
convertCompilerOptionsFromJsonfunction takes inanycurrently, and could instead use this hypothetical interface.
Examples
TypeScript wrapping libraries can let consumers override tsconfig options
import { Plugin } from 'rollup';
import { JsonCompilerOptions } from 'typescript';
interface Options extends JsonCompilerOptions {
customOptions?: string;
}
export default function rollupPluginTypescript(options?: Options): Plugin;
Strict typing for convertCompilerOptionsFromJson
import { convertCompilerOptionsFromJson } from 'typescript';
// Type error
const opts = convertCompilerOptionsFromJson({ allowJs: 'true' }, process.cwd());
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the public CompilerOptions declaration linked in lib/typescript.d.ts and the convertCompilerOptionsFromJson entry point in src/compiler/commandLineParser.ts. Define the JSON-shaped options interface and expose it publicly, then ensure the conversion function accepts it while preserving the requested type checking behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, compilers
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100