microsoft / microsoft/TypeScript
Statically match namespace names using `new Function().name`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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:

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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con l’esempio TypeScript e l’errore segnalato “Cannot use namespace ApiDoc as a type”. Determina se la ricerca dell’interfaccia basata sul nome della funzione richiesta è una funzionalità del compilatore e definisci il comportamento previsto del controllo dei tipi; il lavoro sarà completo quando consentirà di usare le definizioni di tipo condivise previste senza quell’errore, con test che coprano il modello dimostrato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100