Skip to content

Handle blockedStringType #1266

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 2 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions internal/ast/nodeflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ const (
NodeFlagsJsonFile NodeFlags = 1 << 25 // If node was parsed in a Json
NodeFlagsDeprecated NodeFlags = 1 << 26 // If has '@deprecated' JSDoc tag

NodeFlagsSkipDirectInference NodeFlags = 1 << 27 // If the node should skip direct type inference.

NodeFlagsBlockScoped = NodeFlagsLet | NodeFlagsConst | NodeFlagsUsing
NodeFlagsConstant = NodeFlagsConst | NodeFlagsUsing
NodeFlagsAwaitUsing = NodeFlagsConst | NodeFlagsUsing // Variable declaration (NOTE: on a single node these flags would otherwise be mutually exclusive)
Expand Down
4 changes: 3 additions & 1 deletion internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7352,7 +7352,9 @@ func (c *Checker) checkExpressionWorker(node *ast.Node, checkMode CheckMode) *Ty
case ast.KindNullKeyword:
return c.nullWideningType
case ast.KindStringLiteral, ast.KindNoSubstitutionTemplateLiteral:
// !!! Handle blockedStringType
if c.isSkipDirectInferenceNode(node) {
return c.blockedStringType
}
return c.getFreshTypeOfLiteralType(c.getStringLiteralType(node.Text()))
case ast.KindNumericLiteral:
c.checkGrammarNumericLiteral(node.AsNumericLiteral())
Expand Down
17 changes: 8 additions & 9 deletions internal/checker/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,28 +585,27 @@ func (c *Checker) getResolvedSignatureWorker(node *ast.Node, checkMode CheckMode
}

func (c *Checker) GetCandidateSignaturesForStringLiteralCompletions(call *ast.CallLikeExpression, editingArgument *ast.Node) []*Signature {
candidatesSet := collections.Set[*Signature]{}

// first, get candidates when inference is blocked from the source node.
candidates := runWithInferenceBlockedFromSourceNode(c, editingArgument, func() []*Signature {
_, blockedInferenceCandidates := c.getResolvedSignatureWorker(call, CheckModeNormal, 0)
return blockedInferenceCandidates
})
for _, candidate := range candidates {
candidatesSet.Add(candidate)
}
candidatesSet := collections.NewSetFromItems(candidates...)

// next, get candidates where the source node is considered for inference.
candidates = runWithoutResolvedSignatureCaching(c, editingArgument, func() []*Signature {
otherCandidates := runWithoutResolvedSignatureCaching(c, editingArgument, func() []*Signature {
_, inferenceCandidates := c.getResolvedSignatureWorker(call, CheckModeNormal, 0)
return inferenceCandidates
})

for _, candidate := range candidates {
candidatesSet.Add(candidate)
for _, candidate := range otherCandidates {
if candidatesSet.Has(candidate) {
continue
}
candidates = append(candidates, candidate)
}

return slices.Collect(maps.Keys(candidatesSet.Keys()))
return candidates
}

func (c *Checker) GetTypeParameterAtPosition(s *Signature, pos int) *Type {
Expand Down
4 changes: 0 additions & 4 deletions internal/fourslash/_scripts/failingTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ TestCompletionsJsPropertyAssignment
TestCompletionsJsxAttribute2
TestCompletionsKeyof
TestCompletionsLiteralFromInferenceWithinInferredType3
TestCompletionsLiteralMatchingGenericSignature
TestCompletionsNamespaceName
TestCompletionsNewTarget
TestCompletionsNonExistentImport
Expand Down Expand Up @@ -237,11 +236,8 @@ TestPathCompletionsPackageJsonImportsWildcard9
TestPathCompletionsTypesVersionsLocal
TestPathCompletionsTypesVersionsWildcard2
TestSatisfiesOperatorCompletion
TestStringCompletionsFromGenericConditionalTypesUsingTemplateLiteralTypes
TestStringCompletionsImportOrExportSpecifier
TestStringCompletionsVsEscaping
TestStringLiteralCompletionsForGenericConditionalTypesUsingTemplateLiteralTypes
TestStringLiteralCompletionsInPositionTypedUsingRest
TestStringLiteralTypeCompletionsInTypeArgForNonGeneric1
TestTripleSlashRefPathCompletionAbsolutePaths
TestTripleSlashRefPathCompletionContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestCompletionsLiteralMatchingGenericSignature(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: /a.tsx
declare function bar1<P extends "" | "bar" | "baz">(p: P): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestStringCompletionsFromGenericConditionalTypesUsingTemplateLiteralTypes(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @strict: true
type keyword = "foo" | "bar" | "baz"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestStringLiteralCompletionsForGenericConditionalTypesUsingTemplateLiteralTypes(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = ` type PathOf<T, K extends string, P extends string = ""> =
K extends ` + "`" + `${infer U}.${infer V}` + "`" + `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestStringLiteralCompletionsInPositionTypedUsingRest(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `declare function pick<T extends object, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K>;
declare function pick2<T extends object, K extends (keyof T)[]>(obj: T, ...keys: K): Pick<T, K[number]>;
Expand Down