Skip to content

feat(typescript): allow declare for class properties - #21281

Merged
Dmitry Gozman (dgozman) merged 1 commit into
microsoft:mainfrom
dgozman:babel-ts-allow-declare
Mar 2, 2023
Merged

Dmitry Gozman (dgozman) merged 1 commit into
microsoft:mainfrom
dgozman:babel-ts-allow-declare

Conversation

@dgozman

Copy link
Copy Markdown
Collaborator

This enables allowDeclareFields flag that allows code like:

class Foo {
  declare prop: string;
}

Declaring is a workaround for inheritance vs property initialization issues. https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier

For allowDeclareFields to work, we have to run plugin-transform-typescript before plugin-proposal-class-properties and few others, so this change migrates from preset-typescript that always runs last to individual plugin-transform-typescript, and reorders some plugins.

References #21119.

This enables `allowDeclareFields` flag that allows code like:

```ts
class Foo {
  declare prop: string;
}
```

Declaring is a workaround for inheritance vs property initialization issues.
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier

For `allowDeclareFields` to work, we have to run plugin-transform-typescript
before plugin-proposal-class-properties and few others, so this change
migrates from preset-typescript that always runs last to individual
plugin-transform-typescript, and reorders some plugins.
@dgozman
Dmitry Gozman (dgozman) merged commit a1ba675 into microsoft:main Mar 2, 2023
Max Schmitt (mxschmitt) added a commit to mxschmitt/playwright that referenced this pull request Mar 20, 2023
github-actions Bot added a commit that referenced this pull request Mar 20, 2023
Max Schmitt (mxschmitt) pushed a commit that referenced this pull request Mar 20, 2023
…ass properties (#21281)" (#21806)

This PR cherry-picks the following commits:

- d641cae

Fixes #21794

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants