Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable test
variance-annotations-with-jsx
with babel8 (#14626)
- Loading branch information
1 parent
d85bf6f
commit 3b206e1
Showing
9 changed files
with
4,613 additions
and
61 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
.../babel-generator/test/fixtures/typescript/variance-annotations-with-jsx-babel-7/input.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// valid JSX | ||
<in T>() => {}</in>; | ||
|
||
type Covariant<out T> = { | ||
x: T; | ||
} | ||
|
||
declare let super_covariant: Covariant<unknown>; | ||
declare let sub_covariant: Covariant<string>; | ||
|
||
super_covariant = sub_covariant; | ||
sub_covariant = super_covariant; // Error | ||
|
||
type Contravariant<in T> = { | ||
f: (x: T) => void; | ||
} | ||
|
||
declare let super_contravariant: Contravariant<unknown>; | ||
declare let sub_contravariant: Contravariant<string>; | ||
|
||
super_contravariant = sub_contravariant; // Error | ||
sub_contravariant = super_contravariant; | ||
|
||
type Invariant<in out T> = { | ||
f: (x: T) => T; | ||
} | ||
|
||
declare let super_invariant: Invariant<unknown>; | ||
declare let sub_invariant: Invariant<string>; | ||
|
||
super_invariant = sub_invariant; // Error | ||
sub_invariant = super_invariant; // Error | ||
|
||
// Variance of various type constructors | ||
|
||
type T10<out T> = T; | ||
type T11<in T> = keyof T; | ||
type T12<out T, out K extends keyof T> = T[K]; | ||
type T13<in out T> = T[keyof T]; | ||
|
||
// Variance annotation errors | ||
|
||
type Covariant1<in T> = { // Error | ||
x: T; | ||
} | ||
|
||
type Contravariant1<out T> = keyof T; // Error | ||
|
||
type Contravariant2<out T> = { // Error | ||
f: (x: T) => void; | ||
} | ||
|
||
type Invariant1<in T> = { // Error | ||
f: (x: T) => T; | ||
} | ||
|
||
type Invariant2<out T> = { // Error | ||
f: (x: T) => T; | ||
} | ||
|
||
// Variance in circular types | ||
|
||
type Foo1<in T> = { // Error | ||
x: T; | ||
f: FooFn1<T>; | ||
} | ||
|
||
type FooFn1<T> = (foo: Bar1<T[]>) => void; | ||
|
||
type Bar1<T> = { | ||
value: Foo1<T[]>; | ||
} | ||
|
||
type Foo2<out T> = { // Error | ||
x: T; | ||
f: FooFn2<T>; | ||
} | ||
|
||
type FooFn2<T> = (foo: Bar2<T[]>) => void; | ||
|
||
type Bar2<T> = { | ||
value: Foo2<T[]>; | ||
} | ||
|
||
type Foo3<in out T> = { | ||
x: T; | ||
f: FooFn3<T>; | ||
} | ||
|
||
type FooFn3<T> = (foo: Bar3<T[]>) => void; | ||
|
||
type Bar3<T> = { | ||
value: Foo3<T[]>; | ||
} |
4 changes: 4 additions & 0 deletions
4
...bel-generator/test/fixtures/typescript/variance-annotations-with-jsx-babel-7/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"BABEL_8_BREAKING": false, | ||
"plugins": ["jsx", "typescript"] | ||
} |
78 changes: 78 additions & 0 deletions
78
.../babel-generator/test/fixtures/typescript/variance-annotations-with-jsx-babel-7/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// valid JSX | ||
<in T>() => {}</in>; | ||
type Covariant<out T> = { | ||
x: T; | ||
}; | ||
declare let super_covariant: Covariant<unknown>; | ||
declare let sub_covariant: Covariant<string>; | ||
super_covariant = sub_covariant; | ||
sub_covariant = super_covariant; // Error | ||
|
||
type Contravariant<in T> = { | ||
f: (x: T) => void; | ||
}; | ||
declare let super_contravariant: Contravariant<unknown>; | ||
declare let sub_contravariant: Contravariant<string>; | ||
super_contravariant = sub_contravariant; // Error | ||
|
||
sub_contravariant = super_contravariant; | ||
type Invariant<in out T> = { | ||
f: (x: T) => T; | ||
}; | ||
declare let super_invariant: Invariant<unknown>; | ||
declare let sub_invariant: Invariant<string>; | ||
super_invariant = sub_invariant; // Error | ||
|
||
sub_invariant = super_invariant; // Error | ||
// Variance of various type constructors | ||
|
||
type T10<out T> = T; | ||
type T11<in T> = keyof T; | ||
type T12<out T, out K extends keyof T> = T[K]; | ||
type T13<in out T> = T[keyof T]; // Variance annotation errors | ||
|
||
type Covariant1<in T> = { | ||
// Error | ||
x: T; | ||
}; | ||
type Contravariant1<out T> = keyof T; // Error | ||
|
||
type Contravariant2<out T> = { | ||
// Error | ||
f: (x: T) => void; | ||
}; | ||
type Invariant1<in T> = { | ||
// Error | ||
f: (x: T) => T; | ||
}; | ||
type Invariant2<out T> = { | ||
// Error | ||
f: (x: T) => T; | ||
}; // Variance in circular types | ||
|
||
type Foo1<in T> = { | ||
// Error | ||
x: T; | ||
f: FooFn1<T>; | ||
}; | ||
type FooFn1<T> = (foo: Bar1<T[]>) => void; | ||
type Bar1<T> = { | ||
value: Foo1<T[]>; | ||
}; | ||
type Foo2<out T> = { | ||
// Error | ||
x: T; | ||
f: FooFn2<T>; | ||
}; | ||
type FooFn2<T> = (foo: Bar2<T[]>) => void; | ||
type Bar2<T> = { | ||
value: Foo2<T[]>; | ||
}; | ||
type Foo3<in out T> = { | ||
x: T; | ||
f: FooFn3<T>; | ||
}; | ||
type FooFn3<T> = (foo: Bar3<T[]>) => void; | ||
type Bar3<T> = { | ||
value: Foo3<T[]>; | ||
}; |
11 changes: 9 additions & 2 deletions
11
packages/babel-generator/test/fixtures/typescript/variance-annotations-with-jsx/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
{ | ||
"BABEL_8_BREAKING": false, | ||
"plugins": ["jsx", "typescript"] | ||
"BABEL_8_BREAKING": true, | ||
"plugins": [ | ||
"jsx", | ||
"typescript" | ||
], | ||
"parserOpts": { | ||
"errorRecovery": true | ||
}, | ||
"throwMsg": true | ||
} |
163 changes: 163 additions & 0 deletions
163
...bel-parser/test/fixtures/typescript/types/variance-annotations-with-jsx-babel-7/input.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
// valid JSX | ||
<in T>() => {}</in>; | ||
|
||
type Covariant<out T> = { | ||
x: T; | ||
} | ||
|
||
declare let super_covariant: Covariant<unknown>; | ||
declare let sub_covariant: Covariant<string>; | ||
|
||
super_covariant = sub_covariant; | ||
sub_covariant = super_covariant; // Error | ||
|
||
type Contravariant<in T> = { | ||
f: (x: T) => void; | ||
} | ||
|
||
declare let super_contravariant: Contravariant<unknown>; | ||
declare let sub_contravariant: Contravariant<string>; | ||
|
||
super_contravariant = sub_contravariant; // Error | ||
sub_contravariant = super_contravariant; | ||
|
||
type Invariant<in out T> = { | ||
f: (x: T) => T; | ||
} | ||
|
||
declare let super_invariant: Invariant<unknown>; | ||
declare let sub_invariant: Invariant<string>; | ||
|
||
super_invariant = sub_invariant; // Error | ||
sub_invariant = super_invariant; // Error | ||
|
||
// Variance of various type constructors | ||
|
||
type T10<out T> = T; | ||
type T11<in T> = keyof T; | ||
type T12<out T, out K extends keyof T> = T[K]; | ||
type T13<in out T> = T[keyof T]; | ||
|
||
// Variance annotation errors | ||
|
||
type Covariant1<in T> = { // Error | ||
x: T; | ||
} | ||
|
||
type Contravariant1<out T> = keyof T; // Error | ||
|
||
type Contravariant2<out T> = { // Error | ||
f: (x: T) => void; | ||
} | ||
|
||
type Invariant1<in T> = { // Error | ||
f: (x: T) => T; | ||
} | ||
|
||
type Invariant2<out T> = { // Error | ||
f: (x: T) => T; | ||
} | ||
|
||
// Variance in circular types | ||
|
||
type Foo1<in T> = { // Error | ||
x: T; | ||
f: FooFn1<T>; | ||
} | ||
|
||
type FooFn1<T> = (foo: Bar1<T[]>) => void; | ||
|
||
type Bar1<T> = { | ||
value: Foo1<T[]>; | ||
} | ||
|
||
type Foo2<out T> = { // Error | ||
x: T; | ||
f: FooFn2<T>; | ||
} | ||
|
||
type FooFn2<T> = (foo: Bar2<T[]>) => void; | ||
|
||
type Bar2<T> = { | ||
value: Foo2<T[]>; | ||
} | ||
|
||
type Foo3<in out T> = { | ||
x: T; | ||
f: FooFn3<T>; | ||
} | ||
|
||
type FooFn3<T> = (foo: Bar3<T[]>) => void; | ||
|
||
type Bar3<T> = { | ||
value: Foo3<T[]>; | ||
} | ||
|
||
// Wrong modifier usage | ||
|
||
type T20<public T> = T; // Error | ||
type T21<in out in T> = T; // Error | ||
type T22<in out out T> = T; // Error | ||
type T23<out in T> = T; // Error | ||
|
||
declare function f1<in T>(x: T): void; // Error | ||
declare function f2<out T>(): T; // Error | ||
|
||
class C { | ||
in a = 0; // Error | ||
out b = 0; // Error | ||
} | ||
|
||
// Interface merging | ||
|
||
interface Baz<out T> {} | ||
interface Baz<in T> {} | ||
|
||
declare let baz1: Baz<unknown>; | ||
declare let baz2: Baz<string>; | ||
|
||
baz1 = baz2; // Error | ||
baz2 = baz1; // Error | ||
|
||
// Repro from #44572 | ||
|
||
interface Parent<out A> { | ||
child: Child<A> | null; | ||
parent: Parent<A> | null; | ||
} | ||
|
||
interface Child<A, B = unknown> extends Parent<A> { | ||
readonly a: A; | ||
readonly b: B; | ||
} | ||
|
||
function fn<A>(inp: Child<A>) { | ||
const a: Child<unknown> = inp; | ||
} | ||
|
||
const pu: Parent<unknown> = { child: { a: 0, b: 0, child: null, parent: null }, parent: null }; | ||
const notString: Parent<string> = pu; // Error | ||
|
||
// Repro from comment in #44572 | ||
|
||
declare class StateNode<TContext, in out TEvent extends { type: string }> { | ||
_storedEvent: TEvent; | ||
_action: ActionObject<TEvent>; | ||
_state: StateNode<TContext, any>; | ||
} | ||
|
||
interface ActionObject<TEvent extends { type: string }> { | ||
exec: (meta: StateNode<any, TEvent>) => void; | ||
} | ||
|
||
declare function createMachine<TEvent extends { type: string }>(action: ActionObject<TEvent>): StateNode<any, any>; | ||
|
||
declare function interpret<TContext>(machine: StateNode<TContext, any>): void; | ||
|
||
const machine = createMachine({} as any); | ||
|
||
interpret(machine); | ||
|
||
declare const qq: ActionObject<{ type: "PLAY"; value: number }>; | ||
|
||
createMachine<{ type: "PLAY"; value: number } | { type: "RESET" }>(qq); // Error |
7 changes: 7 additions & 0 deletions
7
...-parser/test/fixtures/typescript/types/variance-annotations-with-jsx-babel-7/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"BABEL_8_BREAKING": false, | ||
"plugins": [ | ||
"jsx", | ||
"typescript" | ||
] | ||
} |
Oops, something went wrong.