Skip to content

Commit 8dc6cca

Browse files
author
Christoph
committed
ports tests from #256
1 parent a7ad7bd commit 8dc6cca

20 files changed

+882
-213
lines changed
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Configuration } from './reusable-types'
2+
3+
function MyDecorator(value: Configuration) {
4+
return function (target: Function) {
5+
console.log(`MyDecorator is called with value: ${value}`)
6+
}
7+
}
8+
9+
@MyDecorator({ property: 42, property2: '42' })
10+
class MyClass {
11+
//...
12+
}

snapshots/input/syntax/src/infer-relationship.ts

-60
This file was deleted.

snapshots/input/syntax/src/inheritance.ts

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1+
import { Superinterface } from './reusable-types'
12
import { Overloader } from './overload'
23

3-
export interface Superinterface {
4-
property: string
5-
interfaceMethod(): string
6-
}
74
export interface IntermediateSuperinterface extends Superinterface {
85
intermediateInterfaceMethod(): string
96
}
@@ -43,10 +40,3 @@ export const objectLiteralImplementation: Superinterface = {
4340
throw new Error('Function not implemented.')
4441
},
4542
}
46-
export function consumesInterface(superInterface: Superinterface): void {}
47-
export function infersInterface(): void {
48-
consumesInterface({
49-
interfaceMethod: (): string => 'inferred',
50-
property: 'inferred',
51-
})
52-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Option } from './reusable-types'
2+
3+
interface Foobar {
4+
foobar: number
5+
}
6+
7+
export function hasArrowFunctionParameter(
8+
something: number,
9+
fn: (foobar: Foobar) => Foobar
10+
): Foobar {
11+
return fn({ foobar: 42 + something })
12+
}
13+
14+
export function consumesArrowFunction(): number {
15+
return (
16+
hasArrowFunctionParameter(1, ({ foobar }) => ({ foobar: foobar + 1 }))
17+
.foobar +
18+
hasArrowFunctionParameter(2, foobar => ({ foobar: foobar.foobar + 2 }))
19+
.foobar
20+
)
21+
}
22+
23+
export function genericArrow(): Foobar[] {
24+
return [1].map<Foobar>(n => ({ foobar: n + 1 }))
25+
}
26+
27+
export function genericArrowOption(): Option<Foobar>[] {
28+
return [1].map<Option<Foobar>>(n => ({ value: { foobar: n + 1 } }))
29+
}
30+
31+
export function genericArrow2(): Foobar[] {
32+
// navigation to `foobar` below does not work with tsserver or scip-java
33+
// because `map` is missing an explicit `map<Foobar>` annotation.
34+
return [1].map(n => ({ foobar: n + 1 }))
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import {
2+
Configuration,
3+
GenericClass,
4+
GenericInterface,
5+
Option,
6+
Superinterface,
7+
} from './reusable-types'
8+
9+
export function consumesInterface(superInterface: Superinterface): void {}
10+
export function consumesArray(superInterface: Superinterface[]): void {}
11+
export function consumesGenericInterface<T>(
12+
genercInterface: GenericInterface<T>
13+
): void {}
14+
15+
export function infersInterface(): void {
16+
consumesInterface({
17+
interfaceMethod: (): string => 'inferred',
18+
property: 'inferred',
19+
})
20+
consumesArray([
21+
{
22+
interfaceMethod: (): string => 'inferred',
23+
property: 'inferred',
24+
},
25+
])
26+
consumesGenericInterface<number>({
27+
interfaceMethod: (): string => 'inferred',
28+
property: 123,
29+
})
30+
consumesGenericInterface<Option<Configuration>[]>({
31+
interfaceMethod: (): string => 'inferred',
32+
property: [{ value: { property: 42, property2: '42' } }],
33+
})
34+
}
35+
export function returnStatementInsideArgumentExpression(): Configuration[] {
36+
if (1 == 1) {
37+
return [1].map<Configuration>((number: number): Configuration => {
38+
const incremented = number + 1
39+
return {
40+
property: incremented,
41+
property2: incremented.toString(),
42+
}
43+
})
44+
} else {
45+
return [1].map<Configuration>(number => {
46+
const incremented = number + 1
47+
return {
48+
property: incremented,
49+
property2: incremented.toString(),
50+
}
51+
})
52+
}
53+
}
54+
55+
export function createGenericClass(): GenericClass<Configuration> {
56+
return new GenericClass<Configuration>([{ property: 1, property2: '2' }])
57+
}
58+
59+
export function handleGenericClass() {
60+
return createGenericClass().map(({ property, property2 }) => ({
61+
property: property + 1,
62+
property2: property2 + '1',
63+
}))
64+
}
65+
66+
export function handleShorthand() {
67+
const property = '42'
68+
const interfaceMethod = (): string => 'inferred'
69+
consumesInterface({
70+
interfaceMethod,
71+
property,
72+
})
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Option } from './reusable-types'
2+
3+
interface Address {
4+
street: string
5+
people: Person[]
6+
}
7+
interface Person {
8+
name: string
9+
address?: Address
10+
}
11+
12+
export function handleNestedObjectLiterals(): Person {
13+
return {
14+
name: 'John',
15+
address: {
16+
street: 'Oxford Street',
17+
people: [
18+
{
19+
name: 'Susan',
20+
},
21+
],
22+
},
23+
}
24+
}
25+
26+
export function handleNestedTypeVariables(): Option<Person> {
27+
return {
28+
value: {
29+
name: 'John',
30+
address: {
31+
street: 'Oxford Street',
32+
people: [
33+
{
34+
name: 'Susan',
35+
},
36+
],
37+
},
38+
},
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { Configuration } from './reusable-types'
2+
3+
function random(): number {
4+
return Math.random()
5+
}
6+
7+
export function handleArrayLiteral(): Configuration[] {
8+
return [
9+
{
10+
property: 41,
11+
property2: '41',
12+
},
13+
]
14+
}
15+
16+
export function returnStatement(): Configuration {
17+
if (random() > 0) {
18+
return {
19+
property: 41,
20+
property2: '41',
21+
}
22+
}
23+
for (let i = 0; i < 9; i++) {
24+
if (random() > i) {
25+
return {
26+
property: 41,
27+
property2: '41',
28+
}
29+
}
30+
}
31+
for (const i of [1, 2, 3]) {
32+
if (random() > i) {
33+
return {
34+
property: 41,
35+
property2: '41',
36+
}
37+
}
38+
}
39+
for (const i in { '1': 2 }) {
40+
if (random() > Number.parseInt(i)) {
41+
return {
42+
property: 41,
43+
property2: '41',
44+
}
45+
}
46+
}
47+
while (random() < 0) {
48+
return {
49+
property: 41,
50+
property2: '41',
51+
}
52+
}
53+
do {
54+
if (random() > 0) {
55+
return {
56+
property: 41,
57+
property2: '41',
58+
}
59+
}
60+
} while (random() < 0)
61+
62+
return {
63+
property: 42,
64+
property2: '41',
65+
}
66+
}
67+
68+
export function constDeclaration(): number[] {
69+
var configuration1: Configuration = {
70+
property: 1,
71+
property2: '1',
72+
}
73+
configuration1 = {
74+
property: 2,
75+
property2: '2',
76+
}
77+
let configuration2: Configuration = {
78+
property: 3,
79+
property2: '3',
80+
}
81+
configuration2.property = configuration1.property
82+
const configuration3: Configuration = {
83+
property: 4,
84+
property2: '4',
85+
}
86+
return [
87+
configuration1.property,
88+
configuration2.property,
89+
configuration3.property,
90+
]
91+
}

snapshots/input/syntax/src/property-assignment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ type A = { a: string; b: number }
99
export function typedPropertyAssignment(): A {
1010
// prettier-ignore
1111
return { a: 'a', "b": 10 }
12-
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Reusable types for other snapshot tests
2+
3+
export interface Option<A> {
4+
value?: A
5+
}
6+
7+
export interface Numbers {
8+
property: number
9+
}
10+
export interface Strings {
11+
property2: string
12+
}
13+
export type Configuration = Numbers & Strings
14+
15+
export class GenericClass<A> {
16+
constructor(public readonly values: A[]) {}
17+
public map(fn: (a: A) => A): A[] {
18+
return this.values.map(a => fn(a))
19+
}
20+
}
21+
22+
export interface Superinterface {
23+
property: string
24+
interfaceMethod(): string
25+
}
26+
export interface GenericInterface<T> {
27+
property: T
28+
interfaceMethod(): string
29+
}

snapshots/input/syntax/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
33
"outDir": "dist",
4-
"target": "ES2015"
4+
"target": "ES2015",
5+
"experimentalDecorators": true
56
}
67
}

0 commit comments

Comments
 (0)