microsoft / microsoft/TypeScript
In Javascript, `typeof x !== undefined ? t : f` should act like a declaration of `x` in the true branch
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Search Terms:
existence of define typeof undefined
Code
// @noEmit: true
// @allowJs: true
// @checkJs: true
// @strict: true
// @Filename: a.js
if (typeof define !== 'undefined' && define.amd) {
define([], function() {
})
}
// also, nested
exports.storage = 'undefined' != typeof chrome &&
'undefined' != typeof chrome.storage ?
chrome.storage.local :
undefined;
Expected behavior:
The check type define !== undefined should cause the true branch of the conditional to act as if define were declared.
Actual behavior:
Cannot find name 'define'.
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 with the a.js reproduction and its @allowJs, @checkJs, and @strict settings, then run the TypeScript checker against the two typeof patterns. Trace how the checker handles the conditional branches and unresolved names. Done means both examples type-check without a Cannot find name error while preserving the existing behavior for nested checks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100