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

Ts 3.7-beta support #32962

Closed
wants to merge 1 commit into from
Closed

Ts 3.7-beta support #32962

wants to merge 1 commit into from

Conversation

filipesilva
Copy link
Contributor

Just testing to see what breaks if #32946 is followed up by a 3.7-beta update.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@mary-poppins
Copy link

You can preview ee6157b at https://pr32962-ee6157b.ngbuilds.io/.

@filipesilva
Copy link
Contributor Author

microsoft/TypeScript#33693 is a breaking change that affects us. It's easy to work around though:

before:

          const typeReference = type as ts.TypeReference;
          if (typeReference.typeArguments && typeReference.typeArguments.length === 1) {
            return typeReference.typeArguments[0].symbol;
          }

after

          const typeReference = type as ts.TypeReference;
          const typeArguments = this.checker.getTypeArguments(typeReference);
          if (typeArguments.length === 1) {
            return typeArguments[0].symbol;
          }

@atscott atscott added the area: build & ci Related the build and CI infrastructure of the project label Oct 2, 2019
@ngbot ngbot bot added this to the needsTriage milestone Oct 2, 2019
@lppedd
Copy link

lppedd commented Oct 2, 2019

Hi @filipesilva !
I was trying out TS 3.7 on my Angular application. If it can help in some way, I'm receiving an error only on dev builds, while having importHelpers: true and thus using tslib. This doesn't happen with --prod or when importHelpers: false.

ReferenceError: __importDefault is not defined

At, for exampe, template: __importDefault

ErrorComponent = Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"])([
    Object(_angular_core__WEBPACK_IMPORTED_MODULE_1__["Component"])({
        selector: 'tea-error',
        template: __importDefault(__webpack_require__(/*! raw-loader!./error.component.html */ "./node_modules/raw-loader/dist/cjs.js!./src/main/webapp/app/error/error.component.html")).default,
        changeDetection: _angular_core__WEBPACK_IMPORTED_MODULE_1__["ChangeDetectionStrategy"].OnPush
    })
], ErrorComponent);

Obviously I know I should not use 3.7, it's just "for fun".

@mary-poppins
Copy link

You can preview 5838059 at https://pr32962-5838059.ngbuilds.io/.

@filipesilva
Copy link
Contributor Author

Heya @lppedd, thanks for letting us know. I think the integration tests in this repo should catch the same error.

@mary-poppins
Copy link

You can preview 4ac0c72 at https://pr32962-4ac0c72.ngbuilds.io/.

@mary-poppins
Copy link

You can preview a0c0e20 at https://pr32962-a0c0e20.ngbuilds.io/.

@@ -195,8 +195,9 @@ class TypeScriptSymbolQuery implements SymbolQuery {
const type = this.checker.getTypeAtLocation(parameter.type !);
if (type.symbol !.name == 'TemplateRef' && isReferenceType(type)) {
const typeReference = type as ts.TypeReference;
if (typeReference.typeArguments && typeReference.typeArguments.length === 1) {
return typeReference.typeArguments[0].symbol;
const typeArguments = this.checker.getTypeArguments(typeReference);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -9,7 +9,7 @@
import {Type} from '../interface/type';
import {TypeDecorator, makeDecorator} from '../util/decorators';

import {InjectableType, getInjectableDef, ɵɵInjectableDef, ɵɵdefineInjectable} from './interface/defs';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix for

packages/core/src/di/injectable.ts(12,9): error TS2440: Import declaration conflicts with local declaration of 'InjectableType'.

Listed under breaking changes in https://devblogs.microsoft.com/typescript/announcing-typescript-3-7-beta/.

@@ -1269,7 +1269,7 @@ function saveNameToExportMap(
exportsMap[def.exportAs[i]] = index;
}
}
if ((def as ComponentDef<any>).template) exportsMap[''] = index;
exportsMap[''] = index;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix for

packages/core/src/render3/instructions/shared.ts(1272,9): error TS2774: This condition will always return true since the function is always defined. Did 
you mean to call it instead?

Listed under breaking changes in https://devblogs.microsoft.com/typescript/announcing-typescript-3-7-beta/.

Copy link
Member

@JoostK JoostK Oct 7, 2019

Choose a reason for hiding this comment

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

The if guard is there to differentiate between DirectiveDef and ComponentDef, by testing to see if def has a template property. This is probably still relevant, so a better fix might be

Suggested change
exportsMap[''] = index;
if ((def as ComponentDef<any>).template !== undefined) exportsMap[''] = index;

or

Suggested change
exportsMap[''] = index;
if (!!(def as ComponentDef<any>).template) exportsMap[''] = index;

(which is the alternative workaround in the notes)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The cast to ComponentDef<any> looks odd to me since ComponentDef always has a template. It's means "say that def is a ComponentDef, is the template property defined?" to which it makes sense that TS would complain.

Shouldn't the cast be something different then?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that pattern is a bit misleading. In this case, the cast is there as an assumption of it indeed being a ComponentDef, then checking if template actually exists to confirm.

This pattern is often used in functions with type predicates:

export function isComponentDef<T>(def: DirectiveDef<T>|ComponentDef<T>): def is ComponentDef<T> {
  return (def as ComponentDef<T>).template !== undefined;
}

In this case however, the compiler requires the return type to be boolean, so the original guard as written before you changed it would not have compiled in the type guard. I guess the extra function is omitted for code size (although I'm not sure on that one).

The benefit of the "assumed cast" is that there's proper reference tracking, i.e. IDEs know that the template property read does in fact correspond with ComponentDef.template, so e.g. renaming template will correctly update the isComponentDef function.

@filipesilva
Copy link
Contributor Author

filipesilva commented Oct 7, 2019

Compilation currently fails with this error:

Error: rest parameter does not resolve to a reference type
    at ModuleTypeTranslator.getFunctionTypeJSDoc (/home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/sandbox/processwrapper-sandbox/378/execroot/angular/bazel-out/host/bin/packages/bazel/src/ngc-wrapped/ngc-wrapped.sh.runfiles/npm/node_modules/tsickle/src/module_type_translator.js:424:39)
    at visitFunctionLikeDeclaration (/home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/sandbox/processwrapper-sandbox/378/execroot/angular/bazel-out/host/bin/packages/bazel/src/ngc-wrapped/ngc-wrapped.sh.runfiles/npm/node_modules/tsickle/src/jsdoc_transformer.js:527:75)
    at visitor (/home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/sandbox/processwrapper-sandbox/378/execroot/angular/bazel-out/host/bin/packages/bazel/src/ngc-wrapped/ngc-wrapped.sh.runfiles/npm/node_modules/tsickle/src/jsdoc_transformer.js:913:36)
    at visitNodes (/home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/sandbox/processwrapper-sandbox/378/execroot/angular/bazel-out/host/bin/packages/bazel/src/ngc-wrapped/ngc-wrapped.sh.runfiles/npm/node_modules/typescript/lib/typescript.js:70546:48)
    at visitLexicalEnvironment (/home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/sandbox/processwrapper-sandbox/378/execroot/angular/bazel-out/host/bin/packages/bazel/src/ngc-wrapped/ngc-wrapped.sh.runfiles/npm/node_modules/typescript/lib/typescript.js:70579:22)
...

This corresponds to the following code in tsickle:

                        if (type.flags & ts.TypeFlags.Object &&
                            type.objectFlags & ts.ObjectFlags.Reference) {
                            const typeRef = type;
                            if (!typeRef.typeArguments) {
                                throw new Error('rest parameter does not resolve to a reference type');
                            }
                            type = typeRef.typeArguments[0];
                        }

This seems to be another instance of #32962 (comment).

cc @mprobst @IgorMinar

Reported as angular/tsickle#1096

@lppedd
Copy link

lppedd commented Oct 11, 2019

After updating to CLI 8.3.9 I started receiving the following error on build (both dev and prod).
Reverting to 8.3.8 fixes it.

[error] Error: Debug Failure. Invalid cast. The supplied value [object Object] did not pass the test 'isBindableStaticAccessExpression'.
    at Object.cast (/home/edoardo/IdeaProjects/tria-smartea/node_modules/typescript/lib/typescript.js:1488:25)
    at bindSpecialPropertyAssignment (/home/edoardo/IdeaProjects/tria-smartea/node_modules/typescript/lib/typescript.js:31557:53)
    at bindWorker (/home/edoardo/IdeaProjects/tria-smartea/node_modules/typescript/lib/typescript.js:31131:29)
    at bind (/home/edoardo/IdeaProjects/tria-smartea/node_modules/typescript/lib/typescript.js:31010:13)
    at visitNode (/home/edoardo/IdeaProjects/tria-smartea/node_modules/typescript/lib/typescript.js:17672:24)
    at Object.forEachChild (/home/edoardo/IdeaProjects/tria-smartea/node_modules/typescript/lib/typescript.js:17894:21)
    at bindEachChild (/home/edoardo/IdeaProjects/tria-smartea/node_modules/typescript/lib/typescript.js:29627:16)
    at bindBinaryExpressionFlow (/home/edoardo/IdeaProjects/tria-smartea/node_modules/typescript/lib/typescript.js:30330:17)
    at bindChildrenWorker (/home/edoardo/IdeaProjects/tria-smartea/node_modules/typescript/lib/typescript.js:29688:21)
    at bindChildren (/home/edoardo/IdeaProjects/tria-smartea/node_modules/typescript/lib/typescript.js:29597:17)
    at bind (/home/edoardo/IdeaProjects/tria-smartea/node_modules/typescript/lib/typescript.js:31021:21)
    at visitNode (/home/edoardo/IdeaProjects/tria-smartea/node_modules/typescript/lib/typescript.js:17672:24)
    at Object.forEachChild (/home/edoardo/IdeaProjects/tria-smartea/node_modules/typescript/lib/typescript.js:17892:24)
    at bindEachChild (/home/edoardo/IdeaProjects/tria-smartea/node_modules/typescript/lib/typescript.js:29627:16)
    at bindBinaryExpressionFlow (/home/edoardo/IdeaProjects/tria-smartea/node_modules/typescript/lib/typescript.js:30330:17)
    at bindChildrenWorker (/home/edoardo/IdeaProjects/tria-smartea/node_modules/typescript/lib/typescript.js:29688:21)

Latest 3.7-dev.

@filipesilva
Copy link
Contributor Author

@lppedd the __importDefault problem should be fixed in angular/angular-cli#15847.

I'm not sure what that last error is. Was that on ng build?

@lppedd
Copy link

lppedd commented Oct 15, 2019

@filipesilva thanks! And yes, that last Invalid cast error pops up on ng build.
If you need other info let me know, I'll update to 8.3.9 again.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@mary-poppins
Copy link

You can preview 42aef61 at https://pr32962-42aef61.ngbuilds.io/.

@gkalpak
Copy link
Member

gkalpak commented Jan 14, 2020

This seems to have been superceded by #33717. Can we close this, @filipesilva?

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: build & ci Related the build and CI infrastructure of the project cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants