2017-02-22 00:59:19 +03:00
|
|
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
|
|
|
2018-11-25 11:21:14 +03:00
|
|
|
exports[`A.js 1`] = `
|
|
|
|
====================================options=====================================
|
|
|
|
parsers: ["flow"]
|
|
|
|
printWidth: 80
|
|
|
|
| printWidth
|
|
|
|
=====================================input======================================
|
2017-04-12 23:41:51 +03:00
|
|
|
// No indexer should be fine
|
2016-12-23 22:31:38 +03:00
|
|
|
function foo0(): {} {
|
2017-04-12 23:41:51 +03:00
|
|
|
return { foo: "bar" }
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Matching indexer should be fine
|
|
|
|
function foo1(): {[key: string]: string} {
|
2017-04-12 23:41:51 +03:00
|
|
|
return { foo: "bar" }
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Indexer with different key type is an error when it matches
|
|
|
|
function foo2(): {[key: number]: string} {
|
2017-04-12 23:41:51 +03:00
|
|
|
return { foo: "bar" }
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Matching indexer with different value type is an error
|
|
|
|
function foo3(): {[key: string]: number} {
|
2017-04-12 23:41:51 +03:00
|
|
|
return { foo: "bar" }
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Indexer with different key type and different value type is twice an error
|
|
|
|
function foo4(): {[key: number]: number} {
|
2017-04-12 23:41:51 +03:00
|
|
|
return { foo: "bar" }
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// If key exists in object type then indexer is not matched
|
|
|
|
function foo5(): {[key: string]: number; foo: string} {
|
2017-04-12 23:41:51 +03:00
|
|
|
return { foo: "bar" }
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// If key exists in object type then indexer is not matched
|
|
|
|
function foo6(): {[key: number]: number; foo: string} {
|
2017-04-12 23:41:51 +03:00
|
|
|
return { foo: "bar" }
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Should still complain about mistyped properties
|
|
|
|
function foo7(): {[key: string]: number; foo: number} {
|
2017-04-12 23:41:51 +03:00
|
|
|
return { foo: "bar" }
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2018-11-25 11:21:14 +03:00
|
|
|
|
|
|
|
=====================================output=====================================
|
2016-12-23 22:31:38 +03:00
|
|
|
// No indexer should be fine
|
|
|
|
function foo0(): {} {
|
2017-04-12 23:41:51 +03:00
|
|
|
return { foo: "bar" };
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
|
|
|
// Matching indexer should be fine
|
2016-12-23 22:31:38 +03:00
|
|
|
function foo1(): { [key: string]: string } {
|
2017-04-12 23:41:51 +03:00
|
|
|
return { foo: "bar" };
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
|
|
|
// Indexer with different key type is an error when it matches
|
2016-12-23 22:31:38 +03:00
|
|
|
function foo2(): { [key: number]: string } {
|
2017-04-12 23:41:51 +03:00
|
|
|
return { foo: "bar" };
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
|
|
|
// Matching indexer with different value type is an error
|
2016-12-23 22:31:38 +03:00
|
|
|
function foo3(): { [key: string]: number } {
|
2017-04-12 23:41:51 +03:00
|
|
|
return { foo: "bar" };
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
|
|
|
// Indexer with different key type and different value type is twice an error
|
2016-12-23 22:31:38 +03:00
|
|
|
function foo4(): { [key: number]: number } {
|
2017-04-12 23:41:51 +03:00
|
|
|
return { foo: "bar" };
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
|
|
|
// If key exists in object type then indexer is not matched
|
2017-01-05 01:26:44 +03:00
|
|
|
function foo5(): { [key: string]: number, foo: string } {
|
2017-04-12 23:41:51 +03:00
|
|
|
return { foo: "bar" };
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
|
|
|
// If key exists in object type then indexer is not matched
|
2017-01-05 01:26:44 +03:00
|
|
|
function foo6(): { [key: number]: number, foo: string } {
|
2017-04-12 23:41:51 +03:00
|
|
|
return { foo: "bar" };
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
|
|
|
// Should still complain about mistyped properties
|
2017-01-05 01:26:44 +03:00
|
|
|
function foo7(): { [key: string]: number, foo: number } {
|
2017-04-12 23:41:51 +03:00
|
|
|
return { foo: "bar" };
|
2017-01-11 18:16:38 +03:00
|
|
|
}
|
2017-04-12 23:41:51 +03:00
|
|
|
|
2018-11-25 11:21:14 +03:00
|
|
|
================================================================================
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
2018-11-25 11:21:14 +03:00
|
|
|
exports[`multiple.js 1`] = `
|
|
|
|
====================================options=====================================
|
|
|
|
parsers: ["flow"]
|
|
|
|
printWidth: 80
|
|
|
|
| printWidth
|
|
|
|
=====================================input======================================
|
2017-04-12 23:41:51 +03:00
|
|
|
// @flow
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
let tests = [
|
|
|
|
function() {
|
|
|
|
({}: {
|
|
|
|
[k1: string]: string,
|
|
|
|
[k2: number]: number, // error: not supported (yet)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
];
|
2018-11-25 11:21:14 +03:00
|
|
|
|
|
|
|
=====================================output=====================================
|
2016-12-23 22:31:38 +03:00
|
|
|
// @flow
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
let tests = [
|
|
|
|
function() {
|
2017-01-10 05:49:06 +03:00
|
|
|
({}: {
|
|
|
|
[k1: string]: string,
|
2017-02-25 02:46:20 +03:00
|
|
|
[k2: number]: number // error: not supported (yet)
|
2017-01-10 05:49:06 +03:00
|
|
|
});
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-11 18:16:38 +03:00
|
|
|
];
|
2017-04-12 23:41:51 +03:00
|
|
|
|
2018-11-25 11:21:14 +03:00
|
|
|
================================================================================
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|