Update tests for Typescript 3.7 (#38672)

Typescript 3.7 includes a flag that will allow people to migrate to the
Class Fields ECMA proposal as currently specified, which is at Stage 3.
When `--useDefineForClassFields` is turned on, Typescript
issues 3 new errors in places where the current Typescript semantics
would cause errors with the Stage 3 spec.

Two of the errors are very rare. The third shows up whenever classes want
to redeclare the type of a property from a superclass, usually when the
base property's type is `any` or `unknown`.

```ts
class ColumnSizerExample extends React.Component<any, any> {
  context: React.ContextType<typeof MyContext>
}
```

Without `--useDefineForClassFields`, this *only* redeclares the type of
`context`. With `--useDefineForClassFields`, it redeclares the type of
`context` **and** initialises it to `undefined`. This is very surprising.

To avoid this, Typescript 3.7 introduces new syntax for exactly this scenario:

```ts
class ColumnSizerExample extends React.Component<any, any> {
  declare context: React.ContextType<typeof MyContext>
}
```

However, Definitely Typed tests cannot use this new syntax because it
only works with Typescript 3.7, which isn't even in beta until next
week. So this PR uses several other workarounds instead:

1. Moving a constructor initialiser to a property declaration initialiser.
2. Using a dummy initialiser:
3. Adding type annotations so the type of the base property can be correctly inferred.
4. Deleting the declaration when it has the same type as the base. In this case it's redundant.
This commit is contained in:
Nathan Shively-Sanders 2019-09-27 13:01:36 -07:00 committed by GitHub
parent 9ae12bafb1
commit 0f8f845462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 9 additions and 16 deletions

View File

@ -114,7 +114,11 @@ class MyBaseView extends Marionette.View<MyModel> {
}
class MyView extends Marionette.View<MyModel> {
behaviors: any;
behaviors: any = {
DestroyWarn: {
message: 'hello'
}
};
constructor(model: MyModel) {
super({ model });
@ -122,12 +126,6 @@ class MyView extends Marionette.View<MyModel> {
this.ui = {
destroy: '.destroy'
};
this.behaviors = {
DestroyWarn: {
message: 'hello'
}
};
}
template() {

View File

@ -5,7 +5,7 @@ class AuthService extends Ember.Service {
}
class ApplicationController extends Ember.Controller {
model: {};
model = {};
string: string;
transitionToLogin() {}
}

View File

@ -12,13 +12,11 @@ class Example1 extends Ember.Object.extend({
lastName: '',
allNames: Ember.computed('fullName', function() {
return [this.fullName];
}),
}) as Ember.ComputedProperty<string[]>,
fullName: Ember.computed('firstName', 'lastName', function() {
return `${this.firstName} ${this.lastName}`;
})
}) {
allNames!: Ember.ComputedProperty<string[]>;
fullName!: Ember.ComputedProperty<string>;
}
const unwrappedGetters1: UnwrapComputedPropertyGetters<Example1> = {} as any;

View File

@ -5,7 +5,7 @@ class AuthService extends Ember.Service {
}
class ApplicationController extends Ember.Controller {
model: {};
model = {};
string: string;
transitionToLogin() {}
}

View File

@ -699,7 +699,6 @@ const AsyncCanvasLayer = L.GridLayer.extend({
});
export class ExtendedTileLayer extends L.TileLayer {
options: L.TileLayerOptions;
createTile(coords: L.Coords, done: L.DoneCallback) {
const newCoords: L.Coords = (new L.Point(coords.x, coords.y) as L.Coords);
newCoords.z = coords.z;

View File

@ -300,7 +300,6 @@ interface CustomControlOptions extends ControlOptions {
}
class CustomControl extends Control {
element: HTMLElement;
name: string;
mapViewport?: HTMLElement;
private readonly _boundListener: (e: Event) => void;

View File

@ -2,7 +2,6 @@ namespace Components {
export class TestComponent extends polymer.Base {
public field: string = 'foo';
public is: string;
constructor() {
super();

View File

@ -59,7 +59,7 @@ class Mo extends MComponent<Props, State> {
}
class Mo2 extends MComponent2 {
props: Props;
props: Props = { greet: "hi" };
foo() {
this.props.greet;
}