diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b8f20f5b9ad..d85a46bd74f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16743,8 +16743,8 @@ namespace ts { return restType; } } - return isNumericLiteralName(name) && getIndexTypeOfContextualType(type, IndexKind.Number) || - getIndexTypeOfContextualType(type, IndexKind.String); + return isNumericLiteralName(name) && getIndexTypeOfContextualType(t, IndexKind.Number) || + getIndexTypeOfContextualType(t, IndexKind.String); } return undefined; }, /*noReductions*/ true); diff --git a/tests/baselines/reference/unionTypeWithIndexAndMethodSignature.js b/tests/baselines/reference/unionTypeWithIndexAndMethodSignature.js new file mode 100644 index 00000000000..c78435ef0ce --- /dev/null +++ b/tests/baselines/reference/unionTypeWithIndexAndMethodSignature.js @@ -0,0 +1,15 @@ +//// [unionTypeWithIndexAndMethodSignature.ts] +interface Options { + m(x: number): void; + [key: string]: unknown; +} +declare function f(options: number | Options): void; +f({ + m(x) { }, +}); + +//// [unionTypeWithIndexAndMethodSignature.js] +"use strict"; +f({ + m: function (x) { } +}); diff --git a/tests/baselines/reference/unionTypeWithIndexAndMethodSignature.symbols b/tests/baselines/reference/unionTypeWithIndexAndMethodSignature.symbols new file mode 100644 index 00000000000..3eaae1f320d --- /dev/null +++ b/tests/baselines/reference/unionTypeWithIndexAndMethodSignature.symbols @@ -0,0 +1,24 @@ +=== tests/cases/compiler/unionTypeWithIndexAndMethodSignature.ts === +interface Options { +>Options : Symbol(Options, Decl(unionTypeWithIndexAndMethodSignature.ts, 0, 0)) + + m(x: number): void; +>m : Symbol(Options.m, Decl(unionTypeWithIndexAndMethodSignature.ts, 0, 19)) +>x : Symbol(x, Decl(unionTypeWithIndexAndMethodSignature.ts, 1, 6)) + + [key: string]: unknown; +>key : Symbol(key, Decl(unionTypeWithIndexAndMethodSignature.ts, 2, 5)) +} +declare function f(options: number | Options): void; +>f : Symbol(f, Decl(unionTypeWithIndexAndMethodSignature.ts, 3, 1)) +>options : Symbol(options, Decl(unionTypeWithIndexAndMethodSignature.ts, 4, 19)) +>Options : Symbol(Options, Decl(unionTypeWithIndexAndMethodSignature.ts, 0, 0)) + +f({ +>f : Symbol(f, Decl(unionTypeWithIndexAndMethodSignature.ts, 3, 1)) + + m(x) { }, +>m : Symbol(m, Decl(unionTypeWithIndexAndMethodSignature.ts, 5, 3)) +>x : Symbol(x, Decl(unionTypeWithIndexAndMethodSignature.ts, 6, 6)) + +}); diff --git a/tests/baselines/reference/unionTypeWithIndexAndMethodSignature.types b/tests/baselines/reference/unionTypeWithIndexAndMethodSignature.types new file mode 100644 index 00000000000..76607a40167 --- /dev/null +++ b/tests/baselines/reference/unionTypeWithIndexAndMethodSignature.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/unionTypeWithIndexAndMethodSignature.ts === +interface Options { + m(x: number): void; +>m : (x: number) => void +>x : number + + [key: string]: unknown; +>key : string +} +declare function f(options: number | Options): void; +>f : (options: number | Options) => void +>options : number | Options + +f({ +>f({ m(x) { },}) : void +>f : (options: number | Options) => void +>{ m(x) { },} : { m(x: number): void; } + + m(x) { }, +>m : (x: number) => void +>x : number + +}); diff --git a/tests/cases/compiler/unionTypeWithIndexAndMethodSignature.ts b/tests/cases/compiler/unionTypeWithIndexAndMethodSignature.ts new file mode 100644 index 00000000000..f8504b3ce22 --- /dev/null +++ b/tests/cases/compiler/unionTypeWithIndexAndMethodSignature.ts @@ -0,0 +1,9 @@ +// @strict: true +interface Options { + m(x: number): void; + [key: string]: unknown; +} +declare function f(options: number | Options): void; +f({ + m(x) { }, +}); \ No newline at end of file