Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Preserve return type nodes which resolve to errors in declaration emit
  • Loading branch information
weswigham committed May 13, 2024
commit 3d41691b3baf77386e11fe227a18cddbfcba9ef4
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8233,7 +8233,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function serializeReturnTypeForSignatureWorker(context: NodeBuilderContext, signature: Signature) {
const typePredicate = getTypePredicateOfSignature(signature);
const type = getReturnTypeOfSignature(signature);
if (!isErrorType(type) && context.enclosingDeclaration) {
if (context.enclosingDeclaration && (!isErrorType(type) || (context.flags & NodeBuilderFlags.AllowUnresolvedNames))) {
const annotation = signature.declaration && getNonlocalEffectiveReturnTypeAnnotationNode(signature.declaration);
const enclosingDeclarationIgnoringFakeScope = getEnclosingDeclarationIgnoringFakeScope(context.enclosingDeclaration);
if (!!findAncestor(annotation, n => n === enclosingDeclarationIgnoringFakeScope) && annotation) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [declarationLocalAliasOfImportAlias.ts] ////
import { Record } from "./a";
export type Foo<K extends string> = Record<K, number>;

export const obj = {
doThing<K extends string>(_k: K): Foo<K> {
return {} as any;
},
};
//// [declarationLocalAliasOfImportAlias.d.ts] ////
import { Record } from "./a";
export type Foo<K extends string> = Record<K, number>;
export declare const obj: {
doThing<K extends string>(_k: K): Foo<K>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [declarationLocalAliasOfImportAlias.ts] ////
import { Record } from "./a";
export type Foo<K extends string> = Record<K, number>;

export const obj = {
doThing<K extends string>(_k: K): Foo<K> {
return {} as any;
},
};
//// [declarationLocalAliasOfImportAlias.js] ////
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.obj = void 0;
exports.obj = {
doThing: function (_k) {
return {};
},
};
9 changes: 9 additions & 0 deletions tests/cases/transpile/declarationLocalAliasOfImportAlias.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @declaration: true
import { Record } from "./a";
export type Foo<K extends string> = Record<K, number>;

export const obj = {
doThing<K extends string>(_k: K): Foo<K> {
return {} as any;
},
};