mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Prevent looking up symbol for as const from triggering an error (#48464)
This commit is contained in:
parent
df7ed82dd5
commit
a5dae37943
@ -1790,6 +1790,11 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function isConstAssertion(location: Node) {
|
||||
return (isAssertionExpression(location) && isConstTypeReference(location.type))
|
||||
|| (isJSDocTypeTag(location) && isConstTypeReference(location.typeExpression));
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a given name for a given meaning at a given location. An error is reported if the name was not found and
|
||||
* the nameNotFoundMessage argument is not undefined. Returns the resolved symbol, or undefined if no symbol with
|
||||
@ -1831,6 +1836,11 @@ namespace ts {
|
||||
let isInExternalModule = false;
|
||||
|
||||
loop: while (location) {
|
||||
if (name === "const" && isConstAssertion(location)) {
|
||||
// `const` in an `as const` has no symbol, but issues no error because there is no *actual* lookup of the type
|
||||
// (it refers to the constant type of the expression instead)
|
||||
return undefined;
|
||||
}
|
||||
// Locals of a source file are not in scope (because they get merged into the global symbol table)
|
||||
if (location.locals && !isGlobalSourceFile(location)) {
|
||||
if (result = lookup(location.locals, name, meaning)) {
|
||||
|
||||
8
tests/cases/fourslash/asConstRefsNoErrors1.ts
Normal file
8
tests/cases/fourslash/asConstRefsNoErrors1.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////class Tex {
|
||||
//// type = 'Text' as /**/const;
|
||||
////}
|
||||
|
||||
verify.goToDefinition("", []);
|
||||
verify.noErrors();
|
||||
8
tests/cases/fourslash/asConstRefsNoErrors2.ts
Normal file
8
tests/cases/fourslash/asConstRefsNoErrors2.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////class Tex {
|
||||
//// type = </**/const>'Text';
|
||||
////}
|
||||
|
||||
verify.goToDefinition("", []);
|
||||
verify.noErrors();
|
||||
10
tests/cases/fourslash/asConstRefsNoErrors3.ts
Normal file
10
tests/cases/fourslash/asConstRefsNoErrors3.ts
Normal file
@ -0,0 +1,10 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @checkJs: true
|
||||
// @Filename: file.js
|
||||
////class Tex {
|
||||
//// type = (/** @type {/**/const} */'Text');
|
||||
////}
|
||||
|
||||
verify.goToDefinition("", []);
|
||||
verify.noErrors();
|
||||
Loading…
x
Reference in New Issue
Block a user