microsoft / microsoft/TypeScript
Suggestion: Add a way to hint typescript about basic function flow (call orders)
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files, tests, or compiler entry points; start by reviewing TypeScript's control-flow analysis and the linked design goals. Define how declared function-call ordering would affect type checking without changing emitted JavaScript, then verify the constructor/render/componentDidMount and variable-initialization examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100