microsoft / microsoft/TypeScript

Export an interface for JSON `CompilerOptions`

Đang mở
#30,897 3 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Awaiting More Feedback Suggestion
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

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 tsconfig without either requiring the user to import TypeScript enums or rewriting the interface.
  • The convertCompilerOptionsFromJson function takes in any currently, 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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với khai báo công khai CompilerOptions được liên kết trong lib/typescript.d.ts và entry point convertCompilerOptionsFromJson trong src/compiler/commandLineParser.ts. Định nghĩa interface tùy chọn có dạng JSON và expose nó công khai, sau đó đảm bảo hàm chuyển đổi chấp nhận nó mà vẫn giữ nguyên hành vi kiểm tra kiểu được yêu cầu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
typescript
Lĩnh vực
api, compilers
Loại issue
Tính năng
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
38/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.