Skip to content

Commit fb1dc16

Browse files
committed
Merge branch 'main' into guyllian.gomez/yarn-pnp
2 parents 06c8485 + 83b8d2a commit fb1dc16

419 files changed

Lines changed: 9525 additions & 3595 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848

4949
release-build:
5050
if: ${{ github.repository == 'microsoft/typescript-go' && github.event_name != 'merge_group' }}
51-
runs-on: ['self-hosted', '1ES.Pool=TypeScript-1ES-GitHub-XL', '1ES.ImageOverride=azure-linux-3']
51+
runs-on: TypeScript-1ES-GitHub-XL-2
5252
steps:
5353
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
5454
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
@@ -97,7 +97,7 @@ jobs:
9797
- os: ubuntu-latest
9898
name: 'no submodules'
9999
no-submodules: true
100-
- os: ['self-hosted', '1ES.Pool=TypeScript-1ES-GitHub-XL', '1ES.ImageOverride=azure-linux-3']
100+
- os: TypeScript-1ES-GitHub-XL-2
101101
name: 'race mode'
102102
race: true
103103
skip: ${{ github.event_name == 'merge_group' || github.repository != 'microsoft/typescript-go' }}
@@ -191,7 +191,7 @@ jobs:
191191
npx hereby baseline-accept
192192
git add testdata/baselines/reference
193193
git diff --staged --exit-code
194-
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
194+
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
195195
if: ${{ failure() && steps.test.conclusion == 'failure' }}
196196
with:
197197
name: ${{ matrix.config.os }}-${{ (matrix.config.race && 'race') || 'norace' }}-new-baselines-artifact

CHANGES.md

Lines changed: 40 additions & 42 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ This is still a work in progress and is not yet at full feature parity with Type
4444

4545
Definitions:
4646

47-
* **done** aka "believed done": We're not currently aware of any deficits or major left work to do. OK to log bugs
47+
* **done** aka "believed done": We're not currently aware of any deficits or major work left to do. OK to log bugs
4848
* **in progress**: currently being worked on; some features may work and some might not. OK to log panics, but nothing else please
4949
* **prototype**: proof-of-concept only; do not log bugs
5050
* **not ready**: either haven't even started yet, or far enough from ready that you shouldn't bother messing with it yet

internal/ast/utilities.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3058,6 +3058,9 @@ func IsJSDocSingleCommentNodeList(nodeList *NodeList) bool {
30583058
return false
30593059
}
30603060
parent := nodeList.Nodes[0].Parent
3061+
if parent == nil {
3062+
return false
3063+
}
30613064
return IsJSDocSingleCommentNode(parent) && nodeList == parent.CommentList()
30623065
}
30633066

internal/checker/checker.go

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11211,7 +11211,7 @@ func (c *Checker) checkPrivateIdentifierPropertyAccess(leftType *Type, right *as
1121111211
return true
1121211212
}
1121311213
}
11214-
c.error(right, diagnostics.Property_0_is_not_accessible_outside_class_1_because_it_has_a_private_identifier, diagName, scanner.DeclarationNameToString(typeClass.Name()))
11214+
c.error(right, diagnostics.Property_0_is_not_accessible_outside_class_1_because_it_has_a_private_identifier, diagName, c.SymbolToString(typeClass.Symbol()))
1121511215
return true
1121611216
}
1121711217
return false
@@ -22552,17 +22552,75 @@ func (c *Checker) getTypeFromTypeReference(node *ast.Node) *Type {
2255222552
if links.resolvedType == nil {
2255322553
// Cache both the resolved symbol and the resolved type. The resolved symbol is needed when we check the
2255422554
// type reference in checkTypeReferenceNode.
22555-
symbol := c.getSymbolFromTypeReference(node)
2255622555
// handle LS queries on the `const` in `x as const` by resolving to the type of `x`
2255722556
if isConstTypeReference(node) && ast.IsAssertionExpression(node.Parent) {
2255822557
links.resolvedType = c.checkExpressionCached(node.Parent.Expression())
22558+
} else if t := c.getIntendedTypeFromJSDocTypeReference(node); t != nil {
22559+
links.resolvedType = t
2255922560
} else {
22560-
links.resolvedType = c.getTypeReferenceType(node, symbol)
22561+
links.resolvedType = c.getTypeReferenceType(node, c.getSymbolFromTypeReference(node))
2256122562
}
2256222563
}
2256322564
return links.resolvedType
2256422565
}
2256522566

22567+
func (c *Checker) getIntendedTypeFromJSDocTypeReference(node *ast.Node) *Type {
22568+
if node.Flags&ast.NodeFlagsJSDoc != 0 && ast.IsTypeReferenceNode(node) {
22569+
typeName := node.AsTypeReferenceNode().TypeName
22570+
if ast.IsIdentifier(typeName) {
22571+
typeArgs := node.TypeArguments()
22572+
switch typeName.Text() {
22573+
case "String":
22574+
c.checkNoTypeArguments(node, nil)
22575+
return c.stringType
22576+
case "Number":
22577+
c.checkNoTypeArguments(node, nil)
22578+
return c.numberType
22579+
case "BigInt":
22580+
c.checkNoTypeArguments(node, nil)
22581+
return c.bigintType
22582+
case "Boolean":
22583+
c.checkNoTypeArguments(node, nil)
22584+
return c.booleanType
22585+
case "Void":
22586+
c.checkNoTypeArguments(node, nil)
22587+
return c.voidType
22588+
case "Undefined":
22589+
c.checkNoTypeArguments(node, nil)
22590+
return c.undefinedType
22591+
case "Null":
22592+
c.checkNoTypeArguments(node, nil)
22593+
return c.nullType
22594+
case "Function", "function":
22595+
c.checkNoTypeArguments(node, nil)
22596+
return c.globalFunctionType
22597+
case "array":
22598+
if len(typeArgs) == 0 && !c.noImplicitAny {
22599+
return c.anyArrayType
22600+
}
22601+
case "promise":
22602+
if len(typeArgs) == 0 && !c.noImplicitAny {
22603+
return c.createPromiseType(c.anyType)
22604+
}
22605+
case "Object":
22606+
if len(typeArgs) == 2 {
22607+
if recordSymbol := c.getGlobalRecordSymbol(); recordSymbol != nil {
22608+
if indexType := c.getTypeFromTypeNode(typeArgs[0]); c.isValidIndexKeyType(indexType) {
22609+
return c.getTypeAliasInstantiation(recordSymbol, []*Type{indexType, c.getTypeFromTypeNode(typeArgs[1])}, nil)
22610+
}
22611+
}
22612+
return c.anyType
22613+
}
22614+
if !c.noImplicitAny {
22615+
c.checkNoTypeArguments(node, nil)
22616+
return c.anyType
22617+
}
22618+
}
22619+
}
22620+
}
22621+
return nil
22622+
}
22623+
2256622624
func (c *Checker) getSymbolFromTypeReference(node *ast.Node) *ast.Symbol {
2256722625
links := c.symbolNodeLinks.Get(node)
2256822626
if links.resolvedSymbol == nil {
@@ -22710,7 +22768,13 @@ func (c *Checker) getTypeArgumentsFromNode(node *ast.Node) []*Type {
2271022768

2271122769
func (c *Checker) checkNoTypeArguments(node *ast.Node, symbol *ast.Symbol) bool {
2271222770
if len(node.TypeArguments()) != 0 {
22713-
c.error(node, diagnostics.Type_0_is_not_generic, c.symbolToString(symbol))
22771+
var typeName string
22772+
if symbol != nil {
22773+
typeName = c.symbolToString(symbol)
22774+
} else {
22775+
typeName = scanner.DeclarationNameToString(node.AsTypeReferenceNode().TypeName)
22776+
}
22777+
c.error(node, diagnostics.Type_0_is_not_generic, typeName)
2271422778
return false
2271522779
}
2271622780
return true

internal/checker/exports.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ func (c *Checker) GetConstraintOfTypeParameter(typeParameter *Type) *Type {
154154
return c.getConstraintOfTypeParameter(typeParameter)
155155
}
156156

157+
func (c *Checker) GetDefaultFromTypeParameter(typeParameter *Type) *Type {
158+
return c.getDefaultFromTypeParameter(typeParameter)
159+
}
160+
157161
func (c *Checker) GetResolutionModeOverride(node *ast.ImportAttributes, reportErrors bool) core.ResolutionMode {
158162
return c.getResolutionModeOverride(node, reportErrors)
159163
}
@@ -266,3 +270,35 @@ func (c *Checker) GetIndexInfosOfType(t *Type) []*IndexInfo {
266270
func (c *Checker) IsContextSensitive(node *ast.Node) bool {
267271
return c.isContextSensitive(node)
268272
}
273+
274+
func (c *Checker) FillMissingTypeArguments(typeArguments []*Type, typeParameters []*Type, minTypeArgumentCount int, isJavaScriptImplicitAny bool) []*Type {
275+
return c.fillMissingTypeArguments(typeArguments, typeParameters, minTypeArgumentCount, isJavaScriptImplicitAny)
276+
}
277+
278+
func (c *Checker) GetMinTypeArgumentCount(typeParameters []*Type) int {
279+
return c.getMinTypeArgumentCount(typeParameters)
280+
}
281+
282+
func (c *Checker) GetWidenedLiteralType(t *Type) *Type {
283+
return c.getWidenedLiteralType(t)
284+
}
285+
286+
func (c *Checker) IsTypeAssignableTo(source *Type, target *Type) bool {
287+
return c.isTypeAssignableTo(source, target)
288+
}
289+
290+
func (c *Checker) GetUnionTypeEx(types []*Type, unionReduction UnionReduction) *Type {
291+
return c.getUnionTypeEx(types, unionReduction, nil, nil)
292+
}
293+
294+
func (c *Checker) RequiresAddingImplicitUndefined(node *ast.Node) bool {
295+
enclosingDeclaration := ast.FindAncestor(node, ast.IsDeclaration)
296+
if enclosingDeclaration == nil {
297+
enclosingDeclaration = ast.GetSourceFileOfNode(node).AsNode()
298+
}
299+
symbol := node.Symbol()
300+
if symbol == nil {
301+
return false
302+
}
303+
return c.GetEmitResolver().RequiresAddingImplicitUndefined(node, symbol, enclosingDeclaration)
304+
}

internal/checker/grammarchecks.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -883,14 +883,10 @@ func (c *Checker) checkGrammarHeritageClause(node *ast.HeritageClause) bool {
883883
}
884884

885885
func (c *Checker) checkGrammarExpressionWithTypeArguments(node *ast.Node /*Union[ExpressionWithTypeArguments, TypeQuery]*/) bool {
886-
if !ast.IsExpressionWithTypeArguments(node) {
887-
return false
888-
}
889-
exprWithTypeArgs := node.AsExpressionWithTypeArguments()
890-
if node.Expression().Kind == ast.KindImportKeyword && exprWithTypeArgs.TypeArguments != nil {
886+
if ast.IsExpressionWithTypeArguments(node) && node.Expression().Kind == ast.KindImportKeyword && node.TypeArgumentList() != nil {
891887
return c.grammarErrorOnNode(node, diagnostics.This_use_of_import_is_invalid_import_calls_can_be_written_but_they_must_have_parentheses_and_cannot_have_type_arguments)
892888
}
893-
return c.checkGrammarTypeArguments(node, exprWithTypeArgs.TypeArguments)
889+
return c.checkGrammarTypeArguments(node, node.TypeArgumentList())
894890
}
895891

896892
func (c *Checker) checkGrammarClassDeclarationHeritageClauses(node *ast.ClassLikeDeclaration, file *ast.SourceFile) bool {

internal/checker/nodebuilderimpl.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,7 +2114,7 @@ func (b *NodeBuilderImpl) serializeReturnTypeForSignature(signature *Signature,
21142114
if pt != nil {
21152115
// !!! TODO: If annotated type node is a reference with insufficient type arguments, we should still fall back to type serialization
21162116
// see: canReuseTypeNodeAnnotation in strada for context
2117-
returnTypeNode = b.pseudoTypeToNode(pt)
2117+
returnTypeNode = b.pseudoTypeToNodeWithCheckerFallback(pt, returnType)
21182118
}
21192119
}
21202120
restore()
@@ -2202,6 +2202,7 @@ func (b *NodeBuilderImpl) serializeTypeForDeclaration(declaration *ast.Declarati
22022202
b.ctx.flags |= nodebuilder.FlagsAllowUniqueESSymbolType
22032203
}
22042204
var result *ast.Node
2205+
var reportedInferenceFallback bool
22052206
// !!! expandable hover support
22062207
if !b.isActivelyExpanding() && tryReuse && b.ctx.enclosingDeclaration != nil && declaration != nil && (ast.IsAccessor(declaration) || (ast.HasInferredType(declaration) && !ast.NodeIsSynthesized(declaration) && (t.ObjectFlags()&ObjectFlagsRequiresWidening) == 0)) {
22072208
remove := b.addSymbolTypeToContext(symbol, t)
@@ -2211,24 +2212,40 @@ func (b *NodeBuilderImpl) serializeTypeForDeclaration(declaration *ast.Declarati
22112212
} else {
22122213
pt = b.pc.GetTypeOfDeclaration(declaration)
22132214
}
2214-
if b.pseudoTypeEquivalentToType(pt, t, !requiresAddingUndefined && (ast.IsParameterDeclaration(declaration) || ast.IsPropertySignatureDeclaration(declaration) || ast.IsPropertyDeclaration(declaration)) && isOptionalDeclaration(declaration), !b.ctx.suppressReportInferenceFallback) {
2215+
reportErrors := !b.ctx.suppressReportInferenceFallback
2216+
if b.pseudoTypeEquivalentToType(pt, t, !requiresAddingUndefined && (ast.IsParameterDeclaration(declaration) || ast.IsPropertySignatureDeclaration(declaration) || ast.IsPropertyDeclaration(declaration)) && isOptionalDeclaration(declaration), reportErrors) {
22152217
// !!! TODO: If annotated type node is a reference with insufficient type arguments, we should still fall back to type serialization
22162218
// see: canReuseTypeNodeAnnotation in strada for context
22172219
ptt := b.pseudoTypeToType(pt)
22182220
if ptt != nil && requiresAddingUndefined && containsNonMissingUndefinedType(b.ch, t) && !containsNonMissingUndefinedType(b.ch, ptt) {
22192221
pt = pseudochecker.NewPseudoTypeUnion([]*pseudochecker.PseudoType{pt, pseudochecker.PseudoTypeUndefined})
22202222
}
2221-
result = b.pseudoTypeToNode(pt)
2222-
} else if requiresAddingUndefined {
2223-
pt = pseudochecker.NewPseudoTypeUnion([]*pseudochecker.PseudoType{pt, pseudochecker.PseudoTypeUndefined})
2224-
if b.pseudoTypeEquivalentToType(pt, t, false, !b.ctx.suppressReportInferenceFallback) {
2225-
result = b.pseudoTypeToNode(pt)
2223+
result = b.pseudoTypeToNodeWithCheckerFallback(pt, t)
2224+
} else {
2225+
// Equivalence failed; if errors from inferred-with-errors pseudo types were
2226+
// reported, note it so we can suppress nested errors during the fallback
2227+
// typeToTypeNode serialization (mirroring the suppression that
2228+
// pseudoTypeToNodeWithCheckerFallback provides).
2229+
reportedInferenceFallback = reportErrors && pt.Kind == pseudochecker.PseudoTypeKindInferred && len(pt.AsPseudoTypeInferred().ErrorNodes) > 0
2230+
if requiresAddingUndefined {
2231+
pt = pseudochecker.NewPseudoTypeUnion([]*pseudochecker.PseudoType{pt, pseudochecker.PseudoTypeUndefined})
2232+
if b.pseudoTypeEquivalentToType(pt, t, false, reportErrors) {
2233+
result = b.pseudoTypeToNodeWithCheckerFallback(pt, t)
2234+
reportedInferenceFallback = false
2235+
}
22262236
}
22272237
}
22282238
remove()
22292239
}
22302240
if result == nil {
2231-
result = b.typeToTypeNode(t)
2241+
if reportedInferenceFallback {
2242+
oldSuppress := b.ctx.suppressReportInferenceFallback
2243+
b.ctx.suppressReportInferenceFallback = true
2244+
result = b.typeToTypeNode(t)
2245+
b.ctx.suppressReportInferenceFallback = oldSuppress
2246+
} else {
2247+
result = b.typeToTypeNode(t)
2248+
}
22322249
}
22332250
restoreFlags()
22342251
if result == nil {

internal/checker/printer.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (c *Checker) TypeToStringEx(t *Type, enclosingDeclaration *ast.Node, flags
188188

189189
func (c *Checker) typeToStringEx(t *Type, enclosingDeclaration *ast.Node, flags TypeFormatFlags, vc *VerbosityContext) string {
190190
newLine := ""
191-
if vc != nil && vc.Level > 0 {
191+
if flags&TypeFormatFlagsMultilineObjectLiterals != 0 {
192192
newLine = "\n"
193193
}
194194
writer := printer.NewTextWriter(newLine, 0)
@@ -330,7 +330,7 @@ func (c *Checker) signatureToStringEx(signature *Signature, enclosingDeclaration
330330
if enclosingDeclaration != nil {
331331
sourceFile = ast.GetSourceFileOfNode(enclosingDeclaration)
332332
}
333-
if vc != nil && vc.Level > 0 {
333+
if flags&TypeFormatFlagsMultilineObjectLiterals != 0 {
334334
writer := printer.NewTextWriter("\n", 0)
335335
p.Write(sig, sourceFile, getTrailingSemicolonDeferringWriter(writer), nil)
336336
return writer.String()
@@ -443,6 +443,11 @@ func (c *Checker) TypeParameterToStringEx(t *Type, enclosingDeclaration *ast.Nod
443443
return p.Emit(typeParamNode, sourceFile)
444444
}
445445

446+
func (c *Checker) TypeToTypeNodeEx(t *Type, enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, idToSymbol map[*ast.IdentifierNode]*ast.Symbol) *ast.TypeNode {
447+
nodeBuilder := c.getNodeBuilderEx(idToSymbol)
448+
return nodeBuilder.TypeToTypeNode(t, enclosingDeclaration, flags, internalFlags, nil)
449+
}
450+
446451
func (c *Checker) TypePredicateToTypePredicateNode(t *TypePredicate, enclosingDeclaration *ast.Node, flags nodebuilder.Flags, idToSymbol map[*ast.IdentifierNode]*ast.Symbol) *ast.TypePredicateNodeNode {
447452
nodeBuilder := c.getNodeBuilderEx(idToSymbol)
448453
return nodeBuilder.TypePredicateToTypePredicateNode(t, enclosingDeclaration, flags, nodebuilder.InternalFlagsNone, nil)

0 commit comments

Comments
 (0)