Skip to content
Open
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
15 changes: 8 additions & 7 deletions tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,8 @@ func isPropertyImmediatelyReferencedWithinDeclaration(declaration *ast.Node, usa
func (c *Checker) getTypeOnlyAliasDeclaration(symbol *ast.Symbol) *ast.Node {
if symbol.Flags()&ast.SymbolFlagsAlias != 0 {
c.resolveAlias(symbol)
// Alias resolution may fail before recording the declaration's type-only marker.
c.markSymbolOfAliasDeclarationIfTypeOnly(core.FirstOrNil(symbol.Declarations()), nil)
Comment thread
Andarist marked this conversation as resolved.
return c.aliasSymbolLinks.Get(symbol).typeOnlyDeclaration
}
return nil
Expand All @@ -2209,12 +2211,10 @@ func (c *Checker) getTypeOnlyAliasDeclaration(symbol *ast.Symbol) *ast.Node {
// the symbol for the given meaning
func (c *Checker) getTypeOnlyAliasDeclarationEx(symbol *ast.Symbol, meaning ast.SymbolFlags) *ast.Node {
for symbol.Flags()&ast.SymbolFlagsAlias != 0 && symbol.Flags()&meaning == 0 {
resolved := c.resolveAlias(symbol)
links := c.aliasSymbolLinks.Get(symbol)
if links.typeOnlyDeclaration != nil {
return links.typeOnlyDeclaration
if declaration := c.getTypeOnlyAliasDeclaration(symbol); declaration != nil {
return declaration
}
symbol = resolved
symbol = c.resolveAlias(symbol)
}
return nil
}
Expand Down Expand Up @@ -16700,9 +16700,10 @@ func (c *Checker) resolveAlias(symbol *ast.Symbol) *ast.Symbol {

func (c *Checker) resolveIndirectionAlias(source *ast.Symbol, target *ast.Symbol) *ast.Symbol {
result := c.getMergedSymbol(c.resolveAlias(target))
if targetLinks := c.aliasSymbolLinks.Get(target); targetLinks.typeOnlyDeclaration != nil {
// Compute the target's type-only marker before propagating it, even if alias resolution failed.
if typeOnlyDeclaration := c.getTypeOnlyAliasDeclaration(target); typeOnlyDeclaration != nil {
if sourceLinks := c.aliasSymbolLinks.Get(source); sourceLinks.typeOnlyDeclaration == nil {
sourceLinks.typeOnlyDeclaration = targetLinks.typeOnlyDeclaration
sourceLinks.typeOnlyDeclaration = typeOnlyDeclaration
}
}
return result
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
decoratorMetadataTypeOnlyUnresolvedImport.ts(1,22): error TS2307: Cannot find module './missing-default' or its corresponding type declarations.
decoratorMetadataTypeOnlyUnresolvedImport.ts(2,26): error TS2307: Cannot find module './missing-named' or its corresponding type declarations.
decoratorMetadataTypeOnlyUnresolvedImport.ts(3,37): error TS2307: Cannot find module './missing-default-specifier' or its corresponding type declarations.
decoratorMetadataTypeOnlyUnresolvedImport.ts(13,11): error TS1361: 'Foo' cannot be used as a value because it was imported using 'import type'.
decoratorMetadataTypeOnlyUnresolvedImport.ts(14,11): error TS1361: 'Bar' cannot be used as a value because it was imported using 'import type'.
decoratorMetadataTypeOnlyUnresolvedImport.ts(15,11): error TS1361: 'Baz' cannot be used as a value because it was imported using 'import type'.


==== decoratorMetadataTypeOnlyUnresolvedImport.ts (6 errors) ====
import type Foo from "./missing-default";
~~~~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module './missing-default' or its corresponding type declarations.
import { type Bar } from "./missing-named";
~~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module './missing-named' or its corresponding type declarations.
import type { default as Baz } from "./missing-default-specifier";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module './missing-default-specifier' or its corresponding type declarations.

function dec(_target: unknown, _key: unknown) {}

class C {
@dec a!: Foo;
@dec b!: Bar;
@dec c!: Baz;
}

const x = Foo;
~~~
!!! error TS1361: 'Foo' cannot be used as a value because it was imported using 'import type'.
!!! related TS1376 decoratorMetadataTypeOnlyUnresolvedImport.ts:1:8: 'Foo' was imported here.
const y = Bar;
~~~
!!! error TS1361: 'Bar' cannot be used as a value because it was imported using 'import type'.
!!! related TS1376 decoratorMetadataTypeOnlyUnresolvedImport.ts:2:10: 'Bar' was imported here.
const z = Baz;
~~~
!!! error TS1361: 'Baz' cannot be used as a value because it was imported using 'import type'.
!!! related TS1376 decoratorMetadataTypeOnlyUnresolvedImport.ts:3:15: 'Baz' was imported here.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//// [tests/cases/compiler/decoratorMetadataTypeOnlyUnresolvedImport.ts] ////

//// [decoratorMetadataTypeOnlyUnresolvedImport.ts]
import type Foo from "./missing-default";
import { type Bar } from "./missing-named";
import type { default as Baz } from "./missing-default-specifier";

function dec(_target: unknown, _key: unknown) {}

class C {
@dec a!: Foo;
@dec b!: Bar;
@dec c!: Baz;
}

const x = Foo;
const y = Bar;
const z = Baz;


//// [decoratorMetadataTypeOnlyUnresolvedImport.js]
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
function dec(_target, _key) { }
class C {
}
__decorate([
dec,
__metadata("design:type", Object)
], C.prototype, "a", void 0);
__decorate([
dec,
__metadata("design:type", Object)
], C.prototype, "b", void 0);
__decorate([
dec,
__metadata("design:type", Object)
], C.prototype, "c", void 0);
const x = Foo;
const y = Bar;
const z = Baz;
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//// [tests/cases/compiler/decoratorMetadataTypeOnlyUnresolvedImport.ts] ////

=== decoratorMetadataTypeOnlyUnresolvedImport.ts ===
import type Foo from "./missing-default";
>Foo : Symbol(Foo, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 0, 6))

import { type Bar } from "./missing-named";
>Bar : Symbol(Bar, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 1, 8))

import type { default as Baz } from "./missing-default-specifier";
>Baz : Symbol(Baz, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 2, 13))

function dec(_target: unknown, _key: unknown) {}
>dec : Symbol(dec, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 2, 66))
>_target : Symbol(_target, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 4, 13))
>_key : Symbol(_key, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 4, 30))

class C {
>C : Symbol(C, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 4, 48))

@dec a!: Foo;
>dec : Symbol(dec, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 2, 66))
>a : Symbol(C.a, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 6, 9))
>Foo : Symbol(Foo, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 0, 6))

@dec b!: Bar;
>dec : Symbol(dec, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 2, 66))
>b : Symbol(C.b, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 7, 17))
>Bar : Symbol(Bar, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 1, 8))

@dec c!: Baz;
>dec : Symbol(dec, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 2, 66))
>c : Symbol(C.c, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 8, 17))
>Baz : Symbol(Baz, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 2, 13))
}

const x = Foo;
>x : Symbol(x, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 12, 5))
>Foo : Symbol(Foo, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 0, 6))

const y = Bar;
>y : Symbol(y, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 13, 5))
>Bar : Symbol(Bar, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 1, 8))

const z = Baz;
>z : Symbol(z, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 14, 5))
>Baz : Symbol(Baz, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 2, 13))

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//// [tests/cases/compiler/decoratorMetadataTypeOnlyUnresolvedImport.ts] ////

=== decoratorMetadataTypeOnlyUnresolvedImport.ts ===
import type Foo from "./missing-default";
>Foo : any

import { type Bar } from "./missing-named";
>Bar : any

import type { default as Baz } from "./missing-default-specifier";
>default : any
>Baz : any

function dec(_target: unknown, _key: unknown) {}
>dec : (_target: unknown, _key: unknown) => void
>_target : unknown
>_key : unknown

class C {
>C : C

@dec a!: Foo;
>dec : (_target: unknown, _key: unknown) => void
>a : Foo

@dec b!: Bar;
>dec : (_target: unknown, _key: unknown) => void
>b : Bar

@dec c!: Baz;
>dec : (_target: unknown, _key: unknown) => void
>c : Baz
}

const x = Foo;
>x : any
>Foo : any

const y = Bar;
>y : any
>Bar : any

const z = Baz;
>z : any
>Baz : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
decoratorMetadataTypeOnlyUnresolvedImport.ts(1,22): error TS2307: Cannot find module './missing-default' or its corresponding type declarations.
decoratorMetadataTypeOnlyUnresolvedImport.ts(2,26): error TS2307: Cannot find module './missing-named' or its corresponding type declarations.
decoratorMetadataTypeOnlyUnresolvedImport.ts(3,37): error TS2307: Cannot find module './missing-default-specifier' or its corresponding type declarations.
decoratorMetadataTypeOnlyUnresolvedImport.ts(13,11): error TS1361: 'Foo' cannot be used as a value because it was imported using 'import type'.
decoratorMetadataTypeOnlyUnresolvedImport.ts(14,11): error TS1361: 'Bar' cannot be used as a value because it was imported using 'import type'.
decoratorMetadataTypeOnlyUnresolvedImport.ts(15,11): error TS1361: 'Baz' cannot be used as a value because it was imported using 'import type'.


==== decoratorMetadataTypeOnlyUnresolvedImport.ts (6 errors) ====
import type Foo from "./missing-default";
~~~~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module './missing-default' or its corresponding type declarations.
import { type Bar } from "./missing-named";
~~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module './missing-named' or its corresponding type declarations.
import type { default as Baz } from "./missing-default-specifier";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module './missing-default-specifier' or its corresponding type declarations.

function dec(_target: unknown, _key: unknown) {}

class C {
@dec a!: Foo;
@dec b!: Bar;
@dec c!: Baz;
}

const x = Foo;
~~~
!!! error TS1361: 'Foo' cannot be used as a value because it was imported using 'import type'.
!!! related TS1376 decoratorMetadataTypeOnlyUnresolvedImport.ts:1:8: 'Foo' was imported here.
const y = Bar;
~~~
!!! error TS1361: 'Bar' cannot be used as a value because it was imported using 'import type'.
!!! related TS1376 decoratorMetadataTypeOnlyUnresolvedImport.ts:2:10: 'Bar' was imported here.
const z = Baz;
~~~
!!! error TS1361: 'Baz' cannot be used as a value because it was imported using 'import type'.
!!! related TS1376 decoratorMetadataTypeOnlyUnresolvedImport.ts:3:15: 'Baz' was imported here.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//// [tests/cases/compiler/decoratorMetadataTypeOnlyUnresolvedImport.ts] ////

//// [decoratorMetadataTypeOnlyUnresolvedImport.ts]
import type Foo from "./missing-default";
import { type Bar } from "./missing-named";
import type { default as Baz } from "./missing-default-specifier";

function dec(_target: unknown, _key: unknown) {}

class C {
@dec a!: Foo;
@dec b!: Bar;
@dec c!: Baz;
}

const x = Foo;
const y = Bar;
const z = Baz;


//// [decoratorMetadataTypeOnlyUnresolvedImport.js]
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
function dec(_target, _key) { }
class C {
}
__decorate([
dec,
__metadata("design:type", Object)
], C.prototype, "a", void 0);
__decorate([
dec,
__metadata("design:type", Object)
], C.prototype, "b", void 0);
__decorate([
dec,
__metadata("design:type", Object)
], C.prototype, "c", void 0);
const x = Foo;
const y = Bar;
const z = Baz;
export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//// [tests/cases/compiler/decoratorMetadataTypeOnlyUnresolvedImport.ts] ////

=== decoratorMetadataTypeOnlyUnresolvedImport.ts ===
import type Foo from "./missing-default";
>Foo : Symbol(Foo, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 0, 6))

import { type Bar } from "./missing-named";
>Bar : Symbol(Bar, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 1, 8))

import type { default as Baz } from "./missing-default-specifier";
>Baz : Symbol(Baz, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 2, 13))

function dec(_target: unknown, _key: unknown) {}
>dec : Symbol(dec, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 2, 66))
>_target : Symbol(_target, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 4, 13))
>_key : Symbol(_key, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 4, 30))

class C {
>C : Symbol(C, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 4, 48))

@dec a!: Foo;
>dec : Symbol(dec, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 2, 66))
>a : Symbol(C.a, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 6, 9))
>Foo : Symbol(Foo, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 0, 6))

@dec b!: Bar;
>dec : Symbol(dec, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 2, 66))
>b : Symbol(C.b, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 7, 17))
>Bar : Symbol(Bar, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 1, 8))

@dec c!: Baz;
>dec : Symbol(dec, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 2, 66))
>c : Symbol(C.c, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 8, 17))
>Baz : Symbol(Baz, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 2, 13))
}

const x = Foo;
>x : Symbol(x, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 12, 5))
>Foo : Symbol(Foo, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 0, 6))

const y = Bar;
>y : Symbol(y, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 13, 5))
>Bar : Symbol(Bar, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 1, 8))

const z = Baz;
>z : Symbol(z, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 14, 5))
>Baz : Symbol(Baz, Decl(decoratorMetadataTypeOnlyUnresolvedImport.ts, 2, 13))

Loading