microsoft / microsoft/TypeScript

Import Interfaces and/or definitions from URL's pointing to Servers (Not local to machine)

オープン
#31,178 コメント 1 件 リアクション 3 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

Search Terms

  • import url
  • import web address
  • import from server

Suggestion

Hello, My thought process behind this is allowing strictly typed API's to be served for developers to have an easier time developing/consuming API's.

What I am suggesting probably has implications reaching far past my goal such as importing modules or variables or other things over the web which would impact runtime or require downloading resources at compilation time, I do not wish to dive that deep as my purpose is strictly for typing of objects and possibly typescript definition files that are only used during development, I will let any possible discussion delve further into those other topics.

API's are often served at endpoints such as https://www.foo.com/_api/bar; and when we developers want to consume these API's using typescript we have two options, Declare our response object as any, or write an interface that maps what we need from the API so that intellisense can recommend GetNumberOfLegs from our imported object Animal.dog.Get...

Would it be possible to allow the Typescript compiler to evaluate a url like this one (Gist URL Below) during the development/linting phase and utilize the type at that endpoint? This could be done in my case for typing objects that appear in multiple projects by hosting files like this at a publicly available endpoint, or also allow API endpoints to provide an interface that our typescript compilers could read and utilize during development. If used for definition files, then the package manger install of a separate package for third party definitions of a library would also be rendered not needed.

I imagine we would have an import statement at the top of our file that instead of pointing to a local path, would simply point to a web address.
import myObjectInterface from 'https://www.foo.com/_api/v1.3/interfaces/bar';

Non Raw Gist Url:
https://gist.github.com/Metroidaron/48b6bb2ea0cb7b8b2d0e81f82a62ffb6

Use Cases

I want to use this to centralize my own object types that are relevant across multiple projects by creating public interfaces that all my work projects can point to, the current pitfalls of the current system are that to accomplish synchronization across projects and consistency, I would need to either create and install an NPM Package (or some other package manager), use Git SubModules to maintain separate git repositories inside project repositories, or simply copy/paste files.

This would also allow for API's to provide interfaces to the developer, this would increase development speed because there would not be a need to translate an API into an interface for use in a project while maintaining full and accurate strict typing. If an API is strictly typed behind the scenes, I think it would likely be fairly strait forward for the generation of these files to be automated.

Examples

Example 1

import iBasicSampleObject from 'https://gist.githubusercontent.com/Metroidaron/48b6bb2ea0cb7b8b2d0e81f82a62ffb6/raw/1479fc1271eddd1dfef12ccd9da028f546899fe1/BasicSampleObject.ts';
import iEasierToReadExample from 'https://www.foo.com/_api/v1.3/interfaces/bar';

fetch('https://www.foo.com/_api/v1.3/bar', {}).then( httpResponse => {
  httpResponse.json().then( (bar : iEaserToReadExample) => {
    // Bar is now strictly typed based on what the API defines Bar's Type should be. 
    bar.getFunctionOne();
  });
});

Example 2

import iRemoteUserObject from 'https://www.CompanyWebsite.com/DevelopersStuff/iUserObject.ts';

const UserObject : iRemoteUserObject = {
  name : 'Metroidaron',
  ageBracket : 'old'
}

/**
 * UserObject is strictly typed from an external source
 * and can be imported into my companies external website, employee portal, desktop App, Mobile app, and more.
 */
UserObject.ageNumber

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、TypeScript コンパイラーによる import 文と module resolution の処理を確認し、出力される JavaScript を変更せずに、開発中に remote URL を評価する方法に焦点を当てます。提案にある remote interface と definition-file の例を比較し、そのうえで、実装前に取得、キャッシュ、失敗、補完をどのように扱うかを定義します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。