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
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18760,7 +18760,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

function instantiateSymbol(symbol: Symbol, mapper: TypeMapper): Symbol {
const links = getSymbolLinks(symbol);
if (links.type && !couldContainTypeVariables(links.type)) {
if (links.type && !couldContainTypeVariables(links.type) && !(getDeclarationOfKind(symbol, SyntaxKind.SetAccessor) && couldContainTypeVariables(getWriteTypeOfSymbol(symbol)))) {
// If the type of the symbol is already resolved, and if that type could not possibly
// be affected by instantiation, simply return the symbol itself.
return symbol;
Expand Down
44 changes: 44 additions & 0 deletions tests/baselines/reference/divergentAccessorsTypes7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//// [tests/cases/compiler/divergentAccessorsTypes7.ts] ////

//// [divergentAccessorsTypes7.ts]
class Test<S> {
constructor() {}

set value(value: string | ((item: S) => string)) {}

get value(): string {
return null!;
}

// -- Replacing the getter such that the getter/setter types match, removes the error:
// get value(): string | ((item: S) => string) {
// return null!;
// }

// -- Or, replacing the setter such that a concrete type is used, removes the error:
// set value(value: string | ((item: { property: string }) => string)) {}
}

const a = new Test<{
property: string
}>();

a.value = (item) => item.property


//// [divergentAccessorsTypes7.js]
var Test = /** @class */ (function () {
function Test() {
}
Object.defineProperty(Test.prototype, "value", {
get: function () {
return null;
},
set: function (value) { },
enumerable: false,
configurable: true
});
return Test;
}());
var a = new Test();
a.value = function (item) { return item.property; };
48 changes: 48 additions & 0 deletions tests/baselines/reference/divergentAccessorsTypes7.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//// [tests/cases/compiler/divergentAccessorsTypes7.ts] ////

=== divergentAccessorsTypes7.ts ===
class Test<S> {
>Test : Symbol(Test, Decl(divergentAccessorsTypes7.ts, 0, 0))
>S : Symbol(S, Decl(divergentAccessorsTypes7.ts, 0, 11))

constructor() {}

set value(value: string | ((item: S) => string)) {}
>value : Symbol(Test.value, Decl(divergentAccessorsTypes7.ts, 1, 20), Decl(divergentAccessorsTypes7.ts, 3, 55))
>value : Symbol(value, Decl(divergentAccessorsTypes7.ts, 3, 14))
>item : Symbol(item, Decl(divergentAccessorsTypes7.ts, 3, 32))
>S : Symbol(S, Decl(divergentAccessorsTypes7.ts, 0, 11))

get value(): string {
>value : Symbol(Test.value, Decl(divergentAccessorsTypes7.ts, 1, 20), Decl(divergentAccessorsTypes7.ts, 3, 55))

return null!;
}

// -- Replacing the getter such that the getter/setter types match, removes the error:
// get value(): string | ((item: S) => string) {
// return null!;
// }

// -- Or, replacing the setter such that a concrete type is used, removes the error:
// set value(value: string | ((item: { property: string }) => string)) {}
}

const a = new Test<{
>a : Symbol(a, Decl(divergentAccessorsTypes7.ts, 18, 5))
>Test : Symbol(Test, Decl(divergentAccessorsTypes7.ts, 0, 0))

property: string
>property : Symbol(property, Decl(divergentAccessorsTypes7.ts, 18, 20))

}>();

a.value = (item) => item.property
>a.value : Symbol(Test.value, Decl(divergentAccessorsTypes7.ts, 1, 20), Decl(divergentAccessorsTypes7.ts, 3, 55))
>a : Symbol(a, Decl(divergentAccessorsTypes7.ts, 18, 5))
>value : Symbol(Test.value, Decl(divergentAccessorsTypes7.ts, 1, 20), Decl(divergentAccessorsTypes7.ts, 3, 55))
>item : Symbol(item, Decl(divergentAccessorsTypes7.ts, 22, 11))
>item.property : Symbol(property, Decl(divergentAccessorsTypes7.ts, 18, 20))
>item : Symbol(item, Decl(divergentAccessorsTypes7.ts, 22, 11))
>property : Symbol(property, Decl(divergentAccessorsTypes7.ts, 18, 20))

50 changes: 50 additions & 0 deletions tests/baselines/reference/divergentAccessorsTypes7.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//// [tests/cases/compiler/divergentAccessorsTypes7.ts] ////

=== divergentAccessorsTypes7.ts ===
class Test<S> {
>Test : Test<S>

constructor() {}

set value(value: string | ((item: S) => string)) {}
>value : string
>value : string | ((item: S) => string)
>item : S

get value(): string {
>value : string

return null!;
>null! : null
}

// -- Replacing the getter such that the getter/setter types match, removes the error:
// get value(): string | ((item: S) => string) {
// return null!;
// }

// -- Or, replacing the setter such that a concrete type is used, removes the error:
// set value(value: string | ((item: { property: string }) => string)) {}
}

const a = new Test<{
>a : Test<{ property: string; }>
>new Test<{ property: string}>() : Test<{ property: string; }>
>Test : typeof Test

property: string
>property : string

}>();

a.value = (item) => item.property
>a.value = (item) => item.property : (item: { property: string; }) => string
>a.value : string | ((item: { property: string; }) => string)
>a : Test<{ property: string; }>
>value : string | ((item: { property: string; }) => string)
>(item) => item.property : (item: { property: string; }) => string
>item : { property: string; }
>item.property : string
>item : { property: string; }
>property : string

23 changes: 23 additions & 0 deletions tests/cases/compiler/divergentAccessorsTypes7.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Test<S> {
constructor() {}

set value(value: string | ((item: S) => string)) {}

get value(): string {
return null!;
}

// -- Replacing the getter such that the getter/setter types match, removes the error:
// get value(): string | ((item: S) => string) {
// return null!;
// }

// -- Or, replacing the setter such that a concrete type is used, removes the error:
// set value(value: string | ((item: { property: string }) => string)) {}
}

const a = new Test<{
property: string
}>();

a.value = (item) => item.property