Skip to content

Implicit index signatures #7029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 16, 2016
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
Prev Previous commit
Next Next commit
Adding test
  • Loading branch information
ahejlsberg committed Feb 10, 2016
commit bb7ba1dcea57c6ac35391a271e7f5aec0d636972
85 changes: 85 additions & 0 deletions tests/baselines/reference/implicitIndexSignatures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//// [implicitIndexSignatures.ts]
type StringMap = { [x: string]: string };

const empty1 = {};
let empty2: {};
const names1 = { a: "foo", b: "bar" };
let names2: { a: string, b: string };
let map: StringMap;
map = { x: "xxx", y: "yyy" };
map = empty1;
map = empty2;
map = names1;
map = names2;

declare function getStringIndexValue<T>(map: { [x: string]: T }): T;
declare function getNumberIndexValue<T>(map: { [x: number]: T }): T;

function f1() {
const o1 = { a: 1, b: 2 };
let o2: { a: number, b: number };
const v1 = getStringIndexValue(o1);
const v2 = getStringIndexValue(o2);
}

function f2() {
const o1 = { a: "1", b: "2" };
let o2: { a: string, b: string };
const v1 = getStringIndexValue(o1);
const v2 = getStringIndexValue(o2);
}

function f3() {
const o1 = { a: 1, b: "2" };
let o2: { a: number, b: string };
const v1 = getStringIndexValue(o1);
const v2 = getStringIndexValue(o2);
}

function f4() {
const o1 = { 0: "0", 1: "1", count: 2 };
let o2: { 0: string, 1: string, count: number };
const v1 = getStringIndexValue(o1);
const v2 = getStringIndexValue(o2);
const v3 = getNumberIndexValue(o1);
const v4 = getNumberIndexValue(o2);
}


//// [implicitIndexSignatures.js]
var empty1 = {};
var empty2;
var names1 = { a: "foo", b: "bar" };
var names2;
var map;
map = { x: "xxx", y: "yyy" };
map = empty1;
map = empty2;
map = names1;
map = names2;
function f1() {
var o1 = { a: 1, b: 2 };
var o2;
var v1 = getStringIndexValue(o1);
var v2 = getStringIndexValue(o2);
}
function f2() {
var o1 = { a: "1", b: "2" };
var o2;
var v1 = getStringIndexValue(o1);
var v2 = getStringIndexValue(o2);
}
function f3() {
var o1 = { a: 1, b: "2" };
var o2;
var v1 = getStringIndexValue(o1);
var v2 = getStringIndexValue(o2);
}
function f4() {
var o1 = { 0: "0", 1: "1", count: 2 };
var o2;
var v1 = getStringIndexValue(o1);
var v2 = getStringIndexValue(o2);
var v3 = getNumberIndexValue(o1);
var v4 = getNumberIndexValue(o2);
}
166 changes: 166 additions & 0 deletions tests/baselines/reference/implicitIndexSignatures.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
=== tests/cases/compiler/implicitIndexSignatures.ts ===
type StringMap = { [x: string]: string };
>StringMap : Symbol(StringMap, Decl(implicitIndexSignatures.ts, 0, 0))
>x : Symbol(x, Decl(implicitIndexSignatures.ts, 0, 20))

const empty1 = {};
>empty1 : Symbol(empty1, Decl(implicitIndexSignatures.ts, 2, 5))

let empty2: {};
>empty2 : Symbol(empty2, Decl(implicitIndexSignatures.ts, 3, 3))

const names1 = { a: "foo", b: "bar" };
>names1 : Symbol(names1, Decl(implicitIndexSignatures.ts, 4, 5))
>a : Symbol(a, Decl(implicitIndexSignatures.ts, 4, 16))
>b : Symbol(b, Decl(implicitIndexSignatures.ts, 4, 26))

let names2: { a: string, b: string };
>names2 : Symbol(names2, Decl(implicitIndexSignatures.ts, 5, 3))
>a : Symbol(a, Decl(implicitIndexSignatures.ts, 5, 13))
>b : Symbol(b, Decl(implicitIndexSignatures.ts, 5, 24))

let map: StringMap;
>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3))
>StringMap : Symbol(StringMap, Decl(implicitIndexSignatures.ts, 0, 0))

map = { x: "xxx", y: "yyy" };
>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3))
>x : Symbol(x, Decl(implicitIndexSignatures.ts, 7, 7))
>y : Symbol(y, Decl(implicitIndexSignatures.ts, 7, 17))

map = empty1;
>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3))
>empty1 : Symbol(empty1, Decl(implicitIndexSignatures.ts, 2, 5))

map = empty2;
>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3))
>empty2 : Symbol(empty2, Decl(implicitIndexSignatures.ts, 3, 3))

map = names1;
>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3))
>names1 : Symbol(names1, Decl(implicitIndexSignatures.ts, 4, 5))

map = names2;
>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3))
>names2 : Symbol(names2, Decl(implicitIndexSignatures.ts, 5, 3))

declare function getStringIndexValue<T>(map: { [x: string]: T }): T;
>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13))
>T : Symbol(T, Decl(implicitIndexSignatures.ts, 13, 37))
>map : Symbol(map, Decl(implicitIndexSignatures.ts, 13, 40))
>x : Symbol(x, Decl(implicitIndexSignatures.ts, 13, 48))
>T : Symbol(T, Decl(implicitIndexSignatures.ts, 13, 37))
>T : Symbol(T, Decl(implicitIndexSignatures.ts, 13, 37))

declare function getNumberIndexValue<T>(map: { [x: number]: T }): T;
>getNumberIndexValue : Symbol(getNumberIndexValue, Decl(implicitIndexSignatures.ts, 13, 68))
>T : Symbol(T, Decl(implicitIndexSignatures.ts, 14, 37))
>map : Symbol(map, Decl(implicitIndexSignatures.ts, 14, 40))
>x : Symbol(x, Decl(implicitIndexSignatures.ts, 14, 48))
>T : Symbol(T, Decl(implicitIndexSignatures.ts, 14, 37))
>T : Symbol(T, Decl(implicitIndexSignatures.ts, 14, 37))

function f1() {
>f1 : Symbol(f1, Decl(implicitIndexSignatures.ts, 14, 68))

const o1 = { a: 1, b: 2 };
>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 17, 9))
>a : Symbol(a, Decl(implicitIndexSignatures.ts, 17, 16))
>b : Symbol(b, Decl(implicitIndexSignatures.ts, 17, 22))

let o2: { a: number, b: number };
>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 18, 7))
>a : Symbol(a, Decl(implicitIndexSignatures.ts, 18, 13))
>b : Symbol(b, Decl(implicitIndexSignatures.ts, 18, 24))

const v1 = getStringIndexValue(o1);
>v1 : Symbol(v1, Decl(implicitIndexSignatures.ts, 19, 9))
>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13))
>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 17, 9))

const v2 = getStringIndexValue(o2);
>v2 : Symbol(v2, Decl(implicitIndexSignatures.ts, 20, 9))
>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13))
>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 18, 7))
}

function f2() {
>f2 : Symbol(f2, Decl(implicitIndexSignatures.ts, 21, 1))

const o1 = { a: "1", b: "2" };
>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 24, 9))
>a : Symbol(a, Decl(implicitIndexSignatures.ts, 24, 16))
>b : Symbol(b, Decl(implicitIndexSignatures.ts, 24, 24))

let o2: { a: string, b: string };
>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 25, 7))
>a : Symbol(a, Decl(implicitIndexSignatures.ts, 25, 13))
>b : Symbol(b, Decl(implicitIndexSignatures.ts, 25, 24))

const v1 = getStringIndexValue(o1);
>v1 : Symbol(v1, Decl(implicitIndexSignatures.ts, 26, 9))
>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13))
>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 24, 9))

const v2 = getStringIndexValue(o2);
>v2 : Symbol(v2, Decl(implicitIndexSignatures.ts, 27, 9))
>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13))
>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 25, 7))
}

function f3() {
>f3 : Symbol(f3, Decl(implicitIndexSignatures.ts, 28, 1))

const o1 = { a: 1, b: "2" };
>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 31, 9))
>a : Symbol(a, Decl(implicitIndexSignatures.ts, 31, 16))
>b : Symbol(b, Decl(implicitIndexSignatures.ts, 31, 22))

let o2: { a: number, b: string };
>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 32, 7))
>a : Symbol(a, Decl(implicitIndexSignatures.ts, 32, 13))
>b : Symbol(b, Decl(implicitIndexSignatures.ts, 32, 24))

const v1 = getStringIndexValue(o1);
>v1 : Symbol(v1, Decl(implicitIndexSignatures.ts, 33, 9))
>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13))
>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 31, 9))

const v2 = getStringIndexValue(o2);
>v2 : Symbol(v2, Decl(implicitIndexSignatures.ts, 34, 9))
>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13))
>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 32, 7))
}

function f4() {
>f4 : Symbol(f4, Decl(implicitIndexSignatures.ts, 35, 1))

const o1 = { 0: "0", 1: "1", count: 2 };
>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 38, 9))
>count : Symbol(count, Decl(implicitIndexSignatures.ts, 38, 32))

let o2: { 0: string, 1: string, count: number };
>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 39, 7))
>count : Symbol(count, Decl(implicitIndexSignatures.ts, 39, 35))

const v1 = getStringIndexValue(o1);
>v1 : Symbol(v1, Decl(implicitIndexSignatures.ts, 40, 9))
>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13))
>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 38, 9))

const v2 = getStringIndexValue(o2);
>v2 : Symbol(v2, Decl(implicitIndexSignatures.ts, 41, 9))
>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13))
>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 39, 7))

const v3 = getNumberIndexValue(o1);
>v3 : Symbol(v3, Decl(implicitIndexSignatures.ts, 42, 9))
>getNumberIndexValue : Symbol(getNumberIndexValue, Decl(implicitIndexSignatures.ts, 13, 68))
>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 38, 9))

const v4 = getNumberIndexValue(o2);
>v4 : Symbol(v4, Decl(implicitIndexSignatures.ts, 43, 9))
>getNumberIndexValue : Symbol(getNumberIndexValue, Decl(implicitIndexSignatures.ts, 13, 68))
>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 39, 7))
}

Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy