Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into release-5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
typescript-bot committed Jan 25, 2024
2 parents 80ebb9d + 584b314 commit 13b6193
Show file tree
Hide file tree
Showing 21 changed files with 586 additions and 350 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
check-latest: true
- run: npm ci

- uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3.3.3
- uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
with:
path: ~/.cache/dprint
key: ${{ runner.os }}-dprint-${{ hashFiles('package-lock.json', '.dprint.jsonc') }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@e5f05b81d5b6ff8cfa111c80c22c5fd02a384118 # v3.23.0
uses: github/codeql-action/init@0b21cf2492b6b02c465a3e5d7c473717ad7721ba # v3.23.1
with:
config-file: ./.github/codeql/codeql-configuration.yml
# Override language selection by uncommenting this and choosing your languages
Expand All @@ -56,7 +56,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below).
- name: Autobuild
uses: github/codeql-action/autobuild@e5f05b81d5b6ff8cfa111c80c22c5fd02a384118 # v3.23.0
uses: github/codeql-action/autobuild@0b21cf2492b6b02c465a3e5d7c473717ad7721ba # v3.23.1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -70,4 +70,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@e5f05b81d5b6ff8cfa111c80c22c5fd02a384118 # v3.23.0
uses: github/codeql-action/analyze@0b21cf2492b6b02c465a3e5d7c473717ad7721ba # v3.23.1
2 changes: 1 addition & 1 deletion .github/workflows/release-branch-artifact.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
npm pack ./
mv typescript-*.tgz typescript.tgz
- name: Upload built tarfile
uses: actions/upload-artifact@1eb3cb2b3e0f29609092a73eb033bb759a334595 # v4.1.0
uses: actions/upload-artifact@694cdabd8bdb0f10b2cea11669e1bf5453eed0a6 # v4.2.0
with:
name: tgz
path: typescript.tgz
4 changes: 2 additions & 2 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: 'Upload artifact'
uses: actions/upload-artifact@1eb3cb2b3e0f29609092a73eb033bb759a334595 # v4.1.0
uses: actions/upload-artifact@694cdabd8bdb0f10b2cea11669e1bf5453eed0a6 # v4.2.0
with:
name: SARIF file
path: results.sarif
retention-days: 5

# Upload the results to GitHub's code scanning dashboard.
- name: 'Upload to code-scanning'
uses: github/codeql-action/upload-sarif@e5f05b81d5b6ff8cfa111c80c22c5fd02a384118 # v3.23.0
uses: github/codeql-action/upload-sarif@0b21cf2492b6b02c465a3e5d7c473717ad7721ba # v3.23.1
with:
sarif_file: results.sarif
564 changes: 282 additions & 282 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions scripts/eslint/rules/argument-trivia.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ module.exports = createRule({
}

const getSignature = memoize(() => {
if (context.parserServices?.program) {
const parserServices = ESLintUtils.getParserServices(context);
const parserServices = ESLintUtils.getParserServices(context, /*allowWithoutFullTypeInformation*/ true);
if (parserServices.program) {
const checker = parserServices.program.getTypeChecker();
const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);
return checker.getResolvedSignature(tsNode);
Expand Down
20 changes: 9 additions & 11 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39347,20 +39347,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}

function getNonGenericReturnTypeOfSingleCallSignature(funcType: Type) {
function getReturnTypeOfSingleNonGenericCallSignature(funcType: Type) {
const signature = getSingleCallSignature(funcType);
if (signature) {
const returnType = getReturnTypeOfSignature(signature);
if (!signature.typeParameters || !couldContainTypeVariables(returnType)) {
return returnType;
}
if (signature && !signature.typeParameters) {
return getReturnTypeOfSignature(signature);
}
}

function getReturnTypeOfSingleNonGenericSignatureOfCallChain(expr: CallChain) {
const funcType = checkExpression(expr.expression);
const nonOptionalType = getOptionalExpressionType(funcType, expr.expression);
const returnType = getNonGenericReturnTypeOfSingleCallSignature(funcType);
const returnType = getReturnTypeOfSingleNonGenericCallSignature(funcType);
return returnType && propagateOptionalTypeMarker(returnType, expr, nonOptionalType !== funcType);
}

Expand Down Expand Up @@ -39409,7 +39406,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// signature where we can just fetch the return type without checking the arguments.
if (isCallExpression(expr) && expr.expression.kind !== SyntaxKind.SuperKeyword && !isRequireCall(expr, /*requireStringLiteralLikeArgument*/ true) && !isSymbolOrSymbolForCall(expr)) {
return isCallChain(expr) ? getReturnTypeOfSingleNonGenericSignatureOfCallChain(expr) :
getNonGenericReturnTypeOfSingleCallSignature(checkNonNullExpression(expr.expression));
getReturnTypeOfSingleNonGenericCallSignature(checkNonNullExpression(expr.expression));
}
else if (isAssertionExpression(expr) && !isConstTypeReference(expr.type)) {
return getTypeFromTypeNode((expr as TypeAssertion).type);
Expand Down Expand Up @@ -46384,11 +46381,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
);
}

if (!isIllegalExportDefaultInCJS && getIsolatedModules(compilerOptions) && !(sym.flags & SymbolFlags.Value)) {
if (!isIllegalExportDefaultInCJS && !(node.flags & NodeFlags.Ambient) && getIsolatedModules(compilerOptions) && !(sym.flags & SymbolFlags.Value)) {
const nonLocalMeanings = getSymbolFlags(sym, /*excludeTypeOnlyMeanings*/ false, /*excludeLocalMeanings*/ true);
if (
sym.flags & SymbolFlags.Alias
&& resolveAlias(sym) !== unknownSymbol
&& getSymbolFlags(sym, /*excludeTypeOnlyMeanings*/ false, /*excludeLocalMeanings*/ true) & SymbolFlags.Type
&& nonLocalMeanings & SymbolFlags.Type
&& !(nonLocalMeanings & SymbolFlags.Value)
&& (!typeOnlyDeclaration || getSourceFileOfNode(typeOnlyDeclaration) !== getSourceFileOfNode(node))
) {
// import { SomeType } from "./someModule";
Expand Down
11 changes: 10 additions & 1 deletion src/compiler/moduleSpecifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,16 @@ function computeModuleSpecifiers(
redirectPathsSpecifiers = append(redirectPathsSpecifiers, local);
}
else if (pathIsBareSpecifier(local)) {
pathsSpecifiers = append(pathsSpecifiers, local);
if (pathContainsNodeModules(local)) {
// We could be in this branch due to inappropriate use of `baseUrl`, not intentional `paths`
// usage. It's impossible to reason about where to prioritize baseUrl-generated module
// specifiers, but if they contain `/node_modules/`, they're going to trigger a portability
// error, so *at least* don't prioritize those.
relativeSpecifiers = append(relativeSpecifiers, local);
}
else {
pathsSpecifiers = append(pathsSpecifiers, local);
}
}
else if (forAutoImport || !importedFileIsInNodeModules || modulePath.isInNodeModules) {
// Why this extra conditional, not just an `else`? If some path to the file contained
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/arrayFrom.types
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const inputALike: ArrayLike<A> = { length: 0 };
const inputARand = getEither(inputA, inputALike);
>inputARand : ArrayLike<A> | Iterable<A>
>getEither(inputA, inputALike) : ArrayLike<A> | Iterable<A>
>getEither : <T>(in1: Iterable<T>, in2: ArrayLike<T>) => Iterable<T> | ArrayLike<T>
>getEither : <T>(in1: Iterable<T>, in2: ArrayLike<T>) => ArrayLike<T> | Iterable<T>
>inputA : A[]
>inputALike : ArrayLike<A>

Expand Down Expand Up @@ -163,12 +163,12 @@ const result11: B[] = Array.from(inputASet, ({ a }): B => ({ b: a }));
// the ?: as always taking the false branch, narrowing to ArrayLike<T>,
// even when the type is written as : Iterable<T>|ArrayLike<T>
function getEither<T> (in1: Iterable<T>, in2: ArrayLike<T>) {
>getEither : <T>(in1: Iterable<T>, in2: ArrayLike<T>) => Iterable<T> | ArrayLike<T>
>getEither : <T>(in1: Iterable<T>, in2: ArrayLike<T>) => ArrayLike<T> | Iterable<T>
>in1 : Iterable<T>
>in2 : ArrayLike<T>

return Math.random() > 0.5 ? in1 : in2;
>Math.random() > 0.5 ? in1 : in2 : Iterable<T> | ArrayLike<T>
>Math.random() > 0.5 ? in1 : in2 : ArrayLike<T> | Iterable<T>
>Math.random() > 0.5 : boolean
>Math.random() : number
>Math.random : () => number
Expand Down
19 changes: 19 additions & 0 deletions tests/baselines/reference/circularReferenceInReturnType.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
circularReferenceInReturnType.ts(3,7): error TS7022: 'res1' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
circularReferenceInReturnType.ts(9,7): error TS7022: 'res3' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.


==== circularReferenceInReturnType.ts (2 errors) ====
// inference fails for res1 and res2, but ideally should not
declare function fn1<T>(cb: () => T): string;
const res1 = fn1(() => res1);
~~~~
!!! error TS7022: 'res1' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

declare function fn2<T>(): (cb: () => any) => (a: T) => void;
const res2 = fn2()(() => res2);

declare function fn3<T>(): <T2>(cb: (arg: T2) => any) => (a: T) => void;
const res3 = fn3()(() => res3);
~~~~
!!! error TS7022: 'res3' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

49 changes: 25 additions & 24 deletions tests/baselines/reference/circularReferenceInReturnType.symbols
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
//// [tests/cases/compiler/circularReferenceInReturnType.ts] ////

=== circularReferenceInReturnType.ts ===
// inference fails for res1 and res2, but ideally should not
declare function fn1<T>(cb: () => T): string;
>fn1 : Symbol(fn1, Decl(circularReferenceInReturnType.ts, 0, 0))
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 0, 21))
>cb : Symbol(cb, Decl(circularReferenceInReturnType.ts, 0, 24))
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 0, 21))
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 1, 21))
>cb : Symbol(cb, Decl(circularReferenceInReturnType.ts, 1, 24))
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 1, 21))

const res1 = fn1(() => res1);
>res1 : Symbol(res1, Decl(circularReferenceInReturnType.ts, 1, 5))
>res1 : Symbol(res1, Decl(circularReferenceInReturnType.ts, 2, 5))
>fn1 : Symbol(fn1, Decl(circularReferenceInReturnType.ts, 0, 0))
>res1 : Symbol(res1, Decl(circularReferenceInReturnType.ts, 1, 5))
>res1 : Symbol(res1, Decl(circularReferenceInReturnType.ts, 2, 5))

declare function fn2<T>(): (cb: () => any) => (a: T) => void;
>fn2 : Symbol(fn2, Decl(circularReferenceInReturnType.ts, 1, 29))
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 3, 21))
>cb : Symbol(cb, Decl(circularReferenceInReturnType.ts, 3, 28))
>a : Symbol(a, Decl(circularReferenceInReturnType.ts, 3, 47))
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 3, 21))
>fn2 : Symbol(fn2, Decl(circularReferenceInReturnType.ts, 2, 29))
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 4, 21))
>cb : Symbol(cb, Decl(circularReferenceInReturnType.ts, 4, 28))
>a : Symbol(a, Decl(circularReferenceInReturnType.ts, 4, 47))
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 4, 21))

const res2 = fn2()(() => res2);
>res2 : Symbol(res2, Decl(circularReferenceInReturnType.ts, 4, 5))
>fn2 : Symbol(fn2, Decl(circularReferenceInReturnType.ts, 1, 29))
>res2 : Symbol(res2, Decl(circularReferenceInReturnType.ts, 4, 5))
>res2 : Symbol(res2, Decl(circularReferenceInReturnType.ts, 5, 5))
>fn2 : Symbol(fn2, Decl(circularReferenceInReturnType.ts, 2, 29))
>res2 : Symbol(res2, Decl(circularReferenceInReturnType.ts, 5, 5))

declare function fn3<T>(): <T2>(cb: (arg: T2) => any) => (a: T) => void;
>fn3 : Symbol(fn3, Decl(circularReferenceInReturnType.ts, 4, 31))
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 6, 21))
>T2 : Symbol(T2, Decl(circularReferenceInReturnType.ts, 6, 28))
>cb : Symbol(cb, Decl(circularReferenceInReturnType.ts, 6, 32))
>arg : Symbol(arg, Decl(circularReferenceInReturnType.ts, 6, 37))
>T2 : Symbol(T2, Decl(circularReferenceInReturnType.ts, 6, 28))
>a : Symbol(a, Decl(circularReferenceInReturnType.ts, 6, 58))
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 6, 21))
>fn3 : Symbol(fn3, Decl(circularReferenceInReturnType.ts, 5, 31))
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 7, 21))
>T2 : Symbol(T2, Decl(circularReferenceInReturnType.ts, 7, 28))
>cb : Symbol(cb, Decl(circularReferenceInReturnType.ts, 7, 32))
>arg : Symbol(arg, Decl(circularReferenceInReturnType.ts, 7, 37))
>T2 : Symbol(T2, Decl(circularReferenceInReturnType.ts, 7, 28))
>a : Symbol(a, Decl(circularReferenceInReturnType.ts, 7, 58))
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 7, 21))

const res3 = fn3()(() => res3);
>res3 : Symbol(res3, Decl(circularReferenceInReturnType.ts, 7, 5))
>fn3 : Symbol(fn3, Decl(circularReferenceInReturnType.ts, 4, 31))
>res3 : Symbol(res3, Decl(circularReferenceInReturnType.ts, 7, 5))
>res3 : Symbol(res3, Decl(circularReferenceInReturnType.ts, 8, 5))
>fn3 : Symbol(fn3, Decl(circularReferenceInReturnType.ts, 5, 31))
>res3 : Symbol(res3, Decl(circularReferenceInReturnType.ts, 8, 5))

13 changes: 7 additions & 6 deletions tests/baselines/reference/circularReferenceInReturnType.types
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
//// [tests/cases/compiler/circularReferenceInReturnType.ts] ////

=== circularReferenceInReturnType.ts ===
// inference fails for res1 and res2, but ideally should not
declare function fn1<T>(cb: () => T): string;
>fn1 : <T>(cb: () => T) => string
>cb : () => T

const res1 = fn1(() => res1);
>res1 : string
>res1 : any
>fn1(() => res1) : string
>fn1 : <T>(cb: () => T) => string
>() => res1 : () => string
>res1 : string
>() => res1 : () => any
>res1 : any

declare function fn2<T>(): (cb: () => any) => (a: T) => void;
>fn2 : <T>() => (cb: () => any) => (a: T) => void
Expand All @@ -32,10 +33,10 @@ declare function fn3<T>(): <T2>(cb: (arg: T2) => any) => (a: T) => void;
>a : T

const res3 = fn3()(() => res3);
>res3 : (a: unknown) => void
>res3 : any
>fn3()(() => res3) : (a: unknown) => void
>fn3() : <T2>(cb: (arg: T2) => any) => (a: unknown) => void
>fn3 : <T>() => <T2>(cb: (arg: T2) => any) => (a: T) => void
>() => res3 : () => (a: unknown) => void
>res3 : (a: unknown) => void
>() => res3 : () => any
>res3 : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
circularReferenceInReturnType2.ts(39,7): error TS7022: 'A' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.


==== circularReferenceInReturnType2.ts (1 errors) ====
type ObjectType<Source> = {
kind: "object";
__source: (source: Source) => void;
};

type Field<Source, Key extends string> = {
__key: (key: Key) => void;
__source: (source: Source) => void;
};

declare const object: <Source>() => <
Fields extends {
[Key in keyof Fields]: Field<Source, Key & string>;
}
>(config: {
name: string;
fields: Fields | (() => Fields);
}) => ObjectType<Source>;

type InferValueFromObjectType<Type extends ObjectType<any>> =
Type extends ObjectType<infer Source> ? Source : never;

type FieldResolver<Source, TType extends ObjectType<any>> = (
source: Source
) => InferValueFromObjectType<TType>;

type FieldFuncArgs<Source, Type extends ObjectType<any>> = {
type: Type;
resolve: FieldResolver<Source, Type>;
};

declare const field: <Source, Type extends ObjectType<any>, Key extends string>(
field: FieldFuncArgs<Source, Type>
) => Field<Source, Key>;

type Something = { foo: number };

// inference fails here, but ideally should not
const A = object<Something>()({
~
!!! error TS7022: 'A' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
name: "A",
fields: () => ({
a: field({
type: A,
resolve() {
return {
foo: 100,
};
},
}),
}),
});

17 changes: 9 additions & 8 deletions tests/baselines/reference/circularReferenceInReturnType2.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -126,31 +126,32 @@ type Something = { foo: number };
>Something : Symbol(Something, Decl(circularReferenceInReturnType2.ts, 33, 24))
>foo : Symbol(foo, Decl(circularReferenceInReturnType2.ts, 35, 18))

// inference fails here, but ideally should not
const A = object<Something>()({
>A : Symbol(A, Decl(circularReferenceInReturnType2.ts, 37, 5))
>A : Symbol(A, Decl(circularReferenceInReturnType2.ts, 38, 5))
>object : Symbol(object, Decl(circularReferenceInReturnType2.ts, 10, 13))
>Something : Symbol(Something, Decl(circularReferenceInReturnType2.ts, 33, 24))

name: "A",
>name : Symbol(name, Decl(circularReferenceInReturnType2.ts, 37, 31))
>name : Symbol(name, Decl(circularReferenceInReturnType2.ts, 38, 31))

fields: () => ({
>fields : Symbol(fields, Decl(circularReferenceInReturnType2.ts, 38, 12))
>fields : Symbol(fields, Decl(circularReferenceInReturnType2.ts, 39, 12))

a: field({
>a : Symbol(a, Decl(circularReferenceInReturnType2.ts, 39, 18))
>a : Symbol(a, Decl(circularReferenceInReturnType2.ts, 40, 18))
>field : Symbol(field, Decl(circularReferenceInReturnType2.ts, 31, 13))

type: A,
>type : Symbol(type, Decl(circularReferenceInReturnType2.ts, 40, 14))
>A : Symbol(A, Decl(circularReferenceInReturnType2.ts, 37, 5))
>type : Symbol(type, Decl(circularReferenceInReturnType2.ts, 41, 14))
>A : Symbol(A, Decl(circularReferenceInReturnType2.ts, 38, 5))

resolve() {
>resolve : Symbol(resolve, Decl(circularReferenceInReturnType2.ts, 41, 14))
>resolve : Symbol(resolve, Decl(circularReferenceInReturnType2.ts, 42, 14))

return {
foo: 100,
>foo : Symbol(foo, Decl(circularReferenceInReturnType2.ts, 43, 16))
>foo : Symbol(foo, Decl(circularReferenceInReturnType2.ts, 44, 16))

};
},
Expand Down
Loading

0 comments on commit 13b6193

Please sign in to comment.