microsoft / microsoft/TypeScript
Set context of this keyword in definition file
Chưa có ai nhận issue này.
- 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
set this context in typescript definition file
Suggestion
A way to change the context of this keyword in a type definition file. This is admittedly a weird feature since, to my knowledge, it doesn't really align with how modules work. Perhaps there is another way to achieve this use case.
Use Cases
Here's a video of how my application works - https://vimeo.com/315553984
I have an application that allows users to write code which will then be executed via the Function API - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
Here's a simplified version of how the app works at its core -
const userCode = `
console.log(this, foo, bar);
`;
const func = Function('foo', 'bar', userCode);
func.call({myThis: 'hello'}, 'fooString', 'barString');
My app allows users to write their code in Monaco editor and I've successfully added type definitions for the foo and bar variables via the addExtraLib method - https://microsoft.github.io/monaco-editor/api/interfaces/monaco.languages.typescript.languageservicedefaults.html
So when the user starts to type foo intellisense informs them that it is a string. I'd like to do the same for the this keyword.
Examples
See use cases ^
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
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng việc xem xét cách các tệp định nghĩa TypeScript biểu diễn từ khóa this và cách thông tin đó đến được language service của Monaco thông qua addExtraLib. Sử dụng ví dụ về API Function làm trường hợp sử dụng mục tiêu, và xác minh rằng IntelliSense của trình soạn thảo có thể suy luận ngữ cảnh this được yêu cầu mà không thay đổi hành vi runtime của JavaScript.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, typescript
- Lĩnh vực
- compilers
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100