Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downgrade TypeScript to ~3.6.0 #9826

Closed
wants to merge 4 commits into from
Closed

Conversation

lychyi
Copy link
Contributor

@lychyi lychyi commented Feb 11, 2020

Possibly closing in favor of #9847


Issue: Fixes #9463

Storybook version 5.3.x should be on TypeScript 3.6 and not on 3.7.

The "minor" bump in TS versions caused a breaking change. A class of type declarations generated with TS3.7 would not be compatible with TS3.6 and below. This causes users of Storybook 5.3 to either upgrade TS to 3.7 or stay on an older version of Storybook.

For library maintainers, if they upgrade TS to 3.7, they would force their consumers to do so as well to avoid this issue. Given that the leap from TS 3.6 to 3.7 is technically a breaking change, it would make sense for the Storybook 5.3 version line to just hold at ~3.6.0 and wait to upgrade to 3.7 when Storybook 6 gets released (or held until future major versions). This PR does that.

What I did

I specified the workspace package.json dependency to "typescript": '~3.6.0'. This generates declaration files using tsc using 3.6.5 and should play nice with Storybook consumers still using TypeScript 3.6 and below.

A few other changes were made to accommodate this and I've notated it as comments in the file diffs themselves.

@@ -17,7 +17,8 @@ export const axeTest = (customConfig: Partial<CommonConfig> = {}) =>
...customConfig,
async testBody(page, options) {
const parameters = options.context.parameters.a11y;
const include = parameters?.element ?? '#root';
const element = (parameters === null || parameters === undefined) ? undefined : parameters.element;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only place in the codebase that I could find that took advantage of the optional chaining and nullish coalescing operator introduced in 3.7.

I replaced it with the equivalent code here.

@@ -33,6 +33,8 @@
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@angular/compiler-cli": "^8.2.8",
Copy link
Contributor Author

@lychyi lychyi Feb 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two dependencies @angular/compiler-cli and @angular-devkit/build-angular are required for this package but hoisted from a different location (examples/angular-cli here and here).

These two additions to dependencies guarantees that they're here in this package. If these are missing, the build and tests will fail since yarn install nests them in example/angular-cli after changing TypeScript to ~3.6.0 for some reason.

🤷‍♂

@@ -161,7 +161,7 @@ export function applyAngularCliWebpackConfig(baseConfig: any, cliWebpackConfigOp
// todo add type for acc
const entry = [
...baseConfig.entry,
...Object.values(cliStyleConfig.entry).reduce((acc: any, item) => acc.concat(item), []),
...Object.values<any>(cliStyleConfig.entry).reduce((acc: any, item) => acc.concat(item), []),
Copy link
Contributor Author

@lychyi lychyi Feb 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After installing TypeScript ~3.6.0, this line errors out: TS2461: Type 'unknown' is not an array type.

This is because unknown is the type for cliStyleConfig.entry if you don't specify so I just went ahead and updated the generic to match the type (which is any according to my editor).

@lychyi lychyi changed the base branch from master to next February 11, 2020 22:19
@lychyi lychyi changed the base branch from next to master February 11, 2020 22:23
@lychyi lychyi changed the base branch from master to next February 12, 2020 00:31
@@ -49,6 +49,7 @@ const linked = (
}: { onClick: Function; onKeyUp: Function; Link: ComponentType; prefix: string }
) => {
const Linked = React.memo(p => (
// @ts-ignore
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, compiling TS doesn't quite ignore the onKeyUp, it references line 52 instead so I had to add a // @ts-ignore here. I'm not sure if this is different in TS3.7 vs TS3.6.

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lychyi, really great work!!! Per discussion in the issue, I'm not sure whether this should target next or master. Hope one of the typescript guys can comment cc @kroeder @gaetanmaisse

@lychyi lychyi mentioned this pull request Feb 13, 2020
@gaetanmaisse
Copy link
Member

Superseeded by #9847

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.

TS1086: An accessor cannot be declared in an ambient context
3 participants