microsoft / microsoft/TypeScript
Suggestion: Add a way to hint typescript about basic function flow (call orders)
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
Search Terms
"control flow logic", "function call order", "static flow analysis"
Suggestion
Add flow type, for statically declaring some flow logic (order of function calls)
Use Cases
For example, we could tell typescript that the constructor of a React Component will be called before the render, and the render will be called before componentDidMount.
Examples
flow F;
let test: undefined | string;
F1~function first() { //the number of the flow indicates the order.
test = 'wow';
}
F2~function second() {
console.log(test.length); // <== ok, second() must come after first() so we know for sure that test was initialized.
}
example2:
flow LifeCycle;
class Test extends React.Component {
LifeCycle1~constructor(){...}
LifeCycle3~componentDidMount(){...}
LifeCycle2~render(){...}
}
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.
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
L'issue non indica file, test o punti di ingresso del compilatore; inizia esaminando l'analisi del flusso di controllo di TypeScript e gli obiettivi di progettazione collegati. Definisci in che modo l'ordine dichiarato delle chiamate di funzione influirebbe sul controllo dei tipi senza modificare il JavaScript emesso, quindi verifica gli esempi relativi a constructor/render/componentDidMount e all'inizializzazione delle variabili.
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