microsoft / microsoft/TypeScript
Function body is not checked against assertion signature
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.7.0-dev.20191002
Search Terms: assertion signatures, asserts, not checked, unchecked, unsound
Code
function assertIsString(x: number | string): asserts x is string {
}
function test(x: number | string) {
assertIsString(x);
x.toUpperCase();
}
test(4);
Expected behavior:
This incorrect empty implementation of assertIsString should not type check, because there are execution paths through assertIsString that don’t narrow the type of x to string as the type of assertIsString should require.
Actual behavior:
No TS errors. Compiled JS code fails at runtime: TypeError: x.toUpperCase is not a function.
Playground Link: Playground nightly isn’t new enough, but maybe it will be by the time you read this: link.
Related Issues:
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
Start by reproducing the provided TypeScript example and inspect the compiler entry points responsible for assertion signatures and function-body checking; the issue names no source files or tests. Done means the empty assertIsString implementation is rejected while valid assertion implementations remain accepted, with a regression test covering the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100