mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Fixed expando functions with nullish properties (#54728)
This commit is contained in:
parent
97ef321fa0
commit
ec48ce89da
@ -10750,7 +10750,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
}
|
||||
const widened = getWidenedType(addOptionality(type, /*isProperty*/ false, definedInMethod && !definedInConstructor));
|
||||
if (symbol.valueDeclaration && filterType(widened, t => !!(t.flags & ~TypeFlags.Nullable)) === neverType) {
|
||||
if (symbol.valueDeclaration && isInJSFile(symbol.valueDeclaration) && filterType(widened, t => !!(t.flags & ~TypeFlags.Nullable)) === neverType) {
|
||||
reportImplicitAny(symbol.valueDeclaration, anyType);
|
||||
return anyType;
|
||||
}
|
||||
|
||||
75
tests/baselines/reference/expandoFunctionNullishProperty.js
Normal file
75
tests/baselines/reference/expandoFunctionNullishProperty.js
Normal file
@ -0,0 +1,75 @@
|
||||
//// [tests/cases/compiler/expandoFunctionNullishProperty.ts] ////
|
||||
|
||||
//// [expandoFunctionNullishProperty.ts]
|
||||
// mentioned in https://github.com/microsoft/TypeScript/issues/54220
|
||||
|
||||
interface TestNull {
|
||||
(): void;
|
||||
readonly prop: null;
|
||||
}
|
||||
|
||||
export function testNull(): TestNull {
|
||||
function inner() {}
|
||||
inner.prop = null;
|
||||
return inner;
|
||||
}
|
||||
|
||||
interface TestNull2 {
|
||||
(): void;
|
||||
prop: string | null;
|
||||
}
|
||||
|
||||
export function testNull2(): TestNull2 {
|
||||
function inner() {}
|
||||
inner.prop = null;
|
||||
return inner;
|
||||
}
|
||||
|
||||
interface TestUndefined {
|
||||
(): void;
|
||||
readonly prop: undefined;
|
||||
}
|
||||
|
||||
export function testUndefined(): TestUndefined {
|
||||
function inner() {}
|
||||
inner.prop = undefined;
|
||||
return inner;
|
||||
}
|
||||
|
||||
|
||||
//// [expandoFunctionNullishProperty.js]
|
||||
// mentioned in https://github.com/microsoft/TypeScript/issues/54220
|
||||
export function testNull() {
|
||||
function inner() { }
|
||||
inner.prop = null;
|
||||
return inner;
|
||||
}
|
||||
export function testNull2() {
|
||||
function inner() { }
|
||||
inner.prop = null;
|
||||
return inner;
|
||||
}
|
||||
export function testUndefined() {
|
||||
function inner() { }
|
||||
inner.prop = undefined;
|
||||
return inner;
|
||||
}
|
||||
|
||||
|
||||
//// [expandoFunctionNullishProperty.d.ts]
|
||||
interface TestNull {
|
||||
(): void;
|
||||
readonly prop: null;
|
||||
}
|
||||
export declare function testNull(): TestNull;
|
||||
interface TestNull2 {
|
||||
(): void;
|
||||
prop: string | null;
|
||||
}
|
||||
export declare function testNull2(): TestNull2;
|
||||
interface TestUndefined {
|
||||
(): void;
|
||||
readonly prop: undefined;
|
||||
}
|
||||
export declare function testUndefined(): TestUndefined;
|
||||
export {};
|
||||
@ -0,0 +1,78 @@
|
||||
//// [tests/cases/compiler/expandoFunctionNullishProperty.ts] ////
|
||||
|
||||
=== expandoFunctionNullishProperty.ts ===
|
||||
// mentioned in https://github.com/microsoft/TypeScript/issues/54220
|
||||
|
||||
interface TestNull {
|
||||
>TestNull : Symbol(TestNull, Decl(expandoFunctionNullishProperty.ts, 0, 0))
|
||||
|
||||
(): void;
|
||||
readonly prop: null;
|
||||
>prop : Symbol(TestNull.prop, Decl(expandoFunctionNullishProperty.ts, 3, 11))
|
||||
}
|
||||
|
||||
export function testNull(): TestNull {
|
||||
>testNull : Symbol(testNull, Decl(expandoFunctionNullishProperty.ts, 5, 1))
|
||||
>TestNull : Symbol(TestNull, Decl(expandoFunctionNullishProperty.ts, 0, 0))
|
||||
|
||||
function inner() {}
|
||||
>inner : Symbol(inner, Decl(expandoFunctionNullishProperty.ts, 7, 38))
|
||||
|
||||
inner.prop = null;
|
||||
>inner.prop : Symbol(inner.prop, Decl(expandoFunctionNullishProperty.ts, 8, 21))
|
||||
>inner : Symbol(inner, Decl(expandoFunctionNullishProperty.ts, 7, 38))
|
||||
>prop : Symbol(inner.prop, Decl(expandoFunctionNullishProperty.ts, 8, 21))
|
||||
|
||||
return inner;
|
||||
>inner : Symbol(inner, Decl(expandoFunctionNullishProperty.ts, 7, 38))
|
||||
}
|
||||
|
||||
interface TestNull2 {
|
||||
>TestNull2 : Symbol(TestNull2, Decl(expandoFunctionNullishProperty.ts, 11, 1))
|
||||
|
||||
(): void;
|
||||
prop: string | null;
|
||||
>prop : Symbol(TestNull2.prop, Decl(expandoFunctionNullishProperty.ts, 14, 11))
|
||||
}
|
||||
|
||||
export function testNull2(): TestNull2 {
|
||||
>testNull2 : Symbol(testNull2, Decl(expandoFunctionNullishProperty.ts, 16, 1))
|
||||
>TestNull2 : Symbol(TestNull2, Decl(expandoFunctionNullishProperty.ts, 11, 1))
|
||||
|
||||
function inner() {}
|
||||
>inner : Symbol(inner, Decl(expandoFunctionNullishProperty.ts, 18, 40))
|
||||
|
||||
inner.prop = null;
|
||||
>inner.prop : Symbol(inner.prop, Decl(expandoFunctionNullishProperty.ts, 19, 21))
|
||||
>inner : Symbol(inner, Decl(expandoFunctionNullishProperty.ts, 18, 40))
|
||||
>prop : Symbol(inner.prop, Decl(expandoFunctionNullishProperty.ts, 19, 21))
|
||||
|
||||
return inner;
|
||||
>inner : Symbol(inner, Decl(expandoFunctionNullishProperty.ts, 18, 40))
|
||||
}
|
||||
|
||||
interface TestUndefined {
|
||||
>TestUndefined : Symbol(TestUndefined, Decl(expandoFunctionNullishProperty.ts, 22, 1))
|
||||
|
||||
(): void;
|
||||
readonly prop: undefined;
|
||||
>prop : Symbol(TestUndefined.prop, Decl(expandoFunctionNullishProperty.ts, 25, 11))
|
||||
}
|
||||
|
||||
export function testUndefined(): TestUndefined {
|
||||
>testUndefined : Symbol(testUndefined, Decl(expandoFunctionNullishProperty.ts, 27, 1))
|
||||
>TestUndefined : Symbol(TestUndefined, Decl(expandoFunctionNullishProperty.ts, 22, 1))
|
||||
|
||||
function inner() {}
|
||||
>inner : Symbol(inner, Decl(expandoFunctionNullishProperty.ts, 29, 48))
|
||||
|
||||
inner.prop = undefined;
|
||||
>inner.prop : Symbol(inner.prop, Decl(expandoFunctionNullishProperty.ts, 30, 21))
|
||||
>inner : Symbol(inner, Decl(expandoFunctionNullishProperty.ts, 29, 48))
|
||||
>prop : Symbol(inner.prop, Decl(expandoFunctionNullishProperty.ts, 30, 21))
|
||||
>undefined : Symbol(undefined)
|
||||
|
||||
return inner;
|
||||
>inner : Symbol(inner, Decl(expandoFunctionNullishProperty.ts, 29, 48))
|
||||
}
|
||||
|
||||
@ -0,0 +1,72 @@
|
||||
//// [tests/cases/compiler/expandoFunctionNullishProperty.ts] ////
|
||||
|
||||
=== expandoFunctionNullishProperty.ts ===
|
||||
// mentioned in https://github.com/microsoft/TypeScript/issues/54220
|
||||
|
||||
interface TestNull {
|
||||
(): void;
|
||||
readonly prop: null;
|
||||
>prop : null
|
||||
}
|
||||
|
||||
export function testNull(): TestNull {
|
||||
>testNull : () => TestNull
|
||||
|
||||
function inner() {}
|
||||
>inner : { (): void; prop: null; }
|
||||
|
||||
inner.prop = null;
|
||||
>inner.prop = null : null
|
||||
>inner.prop : null
|
||||
>inner : { (): void; prop: null; }
|
||||
>prop : null
|
||||
|
||||
return inner;
|
||||
>inner : { (): void; prop: null; }
|
||||
}
|
||||
|
||||
interface TestNull2 {
|
||||
(): void;
|
||||
prop: string | null;
|
||||
>prop : string | null
|
||||
}
|
||||
|
||||
export function testNull2(): TestNull2 {
|
||||
>testNull2 : () => TestNull2
|
||||
|
||||
function inner() {}
|
||||
>inner : { (): void; prop: null; }
|
||||
|
||||
inner.prop = null;
|
||||
>inner.prop = null : null
|
||||
>inner.prop : null
|
||||
>inner : { (): void; prop: null; }
|
||||
>prop : null
|
||||
|
||||
return inner;
|
||||
>inner : { (): void; prop: null; }
|
||||
}
|
||||
|
||||
interface TestUndefined {
|
||||
(): void;
|
||||
readonly prop: undefined;
|
||||
>prop : undefined
|
||||
}
|
||||
|
||||
export function testUndefined(): TestUndefined {
|
||||
>testUndefined : () => TestUndefined
|
||||
|
||||
function inner() {}
|
||||
>inner : { (): void; prop: undefined; }
|
||||
|
||||
inner.prop = undefined;
|
||||
>inner.prop = undefined : undefined
|
||||
>inner.prop : undefined
|
||||
>inner : { (): void; prop: undefined; }
|
||||
>prop : undefined
|
||||
>undefined : undefined
|
||||
|
||||
return inner;
|
||||
>inner : { (): void; prop: undefined; }
|
||||
}
|
||||
|
||||
38
tests/cases/compiler/expandoFunctionNullishProperty.ts
Normal file
38
tests/cases/compiler/expandoFunctionNullishProperty.ts
Normal file
@ -0,0 +1,38 @@
|
||||
// @strict: true
|
||||
// @target: esnext
|
||||
// @declaration: true
|
||||
|
||||
// mentioned in https://github.com/microsoft/TypeScript/issues/54220
|
||||
|
||||
interface TestNull {
|
||||
(): void;
|
||||
readonly prop: null;
|
||||
}
|
||||
|
||||
export function testNull(): TestNull {
|
||||
function inner() {}
|
||||
inner.prop = null;
|
||||
return inner;
|
||||
}
|
||||
|
||||
interface TestNull2 {
|
||||
(): void;
|
||||
prop: string | null;
|
||||
}
|
||||
|
||||
export function testNull2(): TestNull2 {
|
||||
function inner() {}
|
||||
inner.prop = null;
|
||||
return inner;
|
||||
}
|
||||
|
||||
interface TestUndefined {
|
||||
(): void;
|
||||
readonly prop: undefined;
|
||||
}
|
||||
|
||||
export function testUndefined(): TestUndefined {
|
||||
function inner() {}
|
||||
inner.prop = undefined;
|
||||
return inner;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user