microsoft / microsoft/TypeScript
Allow method type guards
Open
Nobody has claimed this yet.
Awaiting More Feedback
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 2.0.3
Code
Why I can have function type guard:
function hasValue<T>(value: T | undefined): value is T { return value !== undefined; }
but not method type guard:
export class Maybe<T> {
constructor(public value: T | undefined) {}
hasValue(): this.value is T { return this.value !== undefined; }
// ^ '{' or ';' expected.
}
?
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
Reproduce the TypeScript 2.0.3 diagnostic using the standalone function and Maybe method examples in the issue. Trace how type-guard return annotations are parsed and checked, then add coverage showing that a method guard is accepted and narrows the relevant value; done means the method example type-checks without the reported syntax error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100