microsoft / microsoft/TypeScript

Statically match namespace names using `new Function().name`

オープン
#28,539 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

In Discussion Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

I have this bit of code:

import * as express from 'express';
import {RequestHandler} from 'express';

const router = express.Router();

export const register = (v: any) => {
  router.get('/', makeGetFoo(v));
  router.put('/', makePutFoo(v));
};

namespace ApiDoc {
  
  export interface makeGetFoo  {  // <--- i want to share this interface with front-end codebase
    success: boolean
  }
  
  export interface makePutFoo  {  // <--- i want to share this interface with front-end codebase
    success: boolean
  }
}


const makeGetFoo = (v: any): RequestHandler => {
  
  return (req, res, next) => {
    
    res.json(<ApiDoc[makeGetFoo.name]>{success: true});
    
  };
  
};

const makePutFoo = (v: any): RequestHandler => {
  
  return (req, res, next) => {
    
    res.json(<ApiDoc[makePutFoo.name]>{success: true});
    
  };
  
};

my goal is to put the typings in a intermediary file, so that the types can be sourced by the front-end code. Hopefully you understand what I am trying to do.

The problem is I get this:

screenshot from 2018-11-14 17-08-22

Cannot use namespace ApiDoc as a type

What I want to do is create a system where the interface name matches the function name so that I don't have to guess, etc.

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

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

はじめの一歩

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

調査の方向性

TypeScript の例と、報告された「Cannot use namespace ApiDoc as a type」エラーから始めます。要求されている関数名ベースのインターフェース検索がコンパイラーの機能なのかを判断し、期待される型チェックの動作を定義します。完了条件は、意図された共有型定義をそのエラーなしで使用でき、提示されたパターンを対象とするテストがあることです。

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

評価

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

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

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