Skip to content

Fix name resolution of exports in JS #27394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2018

Conversation

sandersn
Copy link
Member

The ad-hoc name resolution rule for exports forgets to check the requested meaning. When getTypeReferenceType calls resolveTypeReferenceName with Type only in order to give an error when the program uses a value like a type, it is incorrectly able to resolve exports instead of producing an error. Then this incorrect symbol gets treated like an alias, which it isn't, causing the assert.

The fix, for now, is to make resolution of exports check the requested meaning so that it only resolves when Value is requested. This makes the above code an error ("Cannot use the namespace 'exports' as a type."), but I think this is fine for a bug fix. We can decide later if exports should behave like other expandos and be a legal type reference.

Note that the name actually does resolve correctly, so JS users will get the desired completions. They'll just have an error to suppress if they have checkJs on.

Fixes #27342

The ad-hoc name resolution rule for `exports` forgets to check the
requested meaning. When `getTypeReferenceType` calls`
resolveTypeReferenceName` with `Type` only in order to give an error
when the program uses a value like a type, it is incorrectly able to
resolve `exports` instead of producing an error. Then this incorrect
symbol gets treated like an alias, which it isn't, causing the assert.

The fix, for now, is to make resolution of `exports` check the requested
meaning so that it only resolves when `Value` is requested. This makes
the above code an error ("Cannot use the namespace 'exports' as a
type."), but I think this is fine for a bug fix. We can decide later if
`exports` should behave like other expandos and be a legal type
reference.

Note that the name actually does resolve correctly, so JS users will get
the desired completions. They'll just have an error to suppress if they
have checkJs on.
@sandersn sandersn added this to the TypeScript 3.1 milestone Sep 27, 2018
@sandersn sandersn merged commit 95dc1f2 into release-3.1 Oct 8, 2018
@sandersn sandersn deleted the js/skip-error-checking-of-exports-as-type branch October 8, 2018 15:53
@sandersn
Copy link
Member Author

sandersn commented Oct 8, 2018

This is now in master as well.

sandersn added a commit that referenced this pull request Oct 8, 2018
The ad-hoc name resolution rule for `exports` forgets to check the
requested meaning. When `getTypeReferenceType` calls`
resolveTypeReferenceName` with `Type` only in order to give an error
when the program uses a value like a type, it is incorrectly able to
resolve `exports` instead of producing an error. Then this incorrect
symbol gets treated like an alias, which it isn't, causing the assert.

The fix, for now, is to make resolution of `exports` check the requested
meaning so that it only resolves when `Value` is requested. This makes
the above code an error ("Cannot use the namespace 'exports' as a
type."), but I think this is fine for a bug fix. We can decide later if
`exports` should behave like other expandos and be a legal type
reference.

Note that the name actually does resolve correctly, so JS users will get
the desired completions. They'll just have an error to suppress if they
have checkJs on.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants