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

Draft
wants to merge 1 commit into
base: master
from

Conversation

@filipesilva
Copy link
Member

filipesilva commented Oct 2, 2019

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

This comment has been minimized.

Copy link

googlebot commented Oct 2, 2019

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.

@googlebot googlebot added the cla: no label Oct 2, 2019
@mary-poppins

This comment has been minimized.

Copy link

mary-poppins commented Oct 2, 2019

@filipesilva

This comment has been minimized.

Copy link
Member Author

filipesilva commented Oct 2, 2019

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;
          }
@ngbot ngbot bot added this to the needsTriage milestone Oct 2, 2019
@lppedd

This comment has been minimized.

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".

@filipesilva filipesilva force-pushed the filipesilva:ts.3.7 branch from ee6157b to 5838059 Oct 7, 2019
@mary-poppins

This comment has been minimized.

Copy link

mary-poppins commented Oct 7, 2019

@filipesilva filipesilva force-pushed the filipesilva:ts.3.7 branch from 5838059 to 4ac0c72 Oct 7, 2019
@filipesilva

This comment has been minimized.

Copy link
Member Author

filipesilva commented Oct 7, 2019

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

@mary-poppins

This comment has been minimized.

Copy link

mary-poppins commented Oct 7, 2019

@filipesilva filipesilva force-pushed the filipesilva:ts.3.7 branch from 4ac0c72 to a0c0e20 Oct 7, 2019
@mary-poppins

This comment has been minimized.

Copy link

mary-poppins commented Oct 7, 2019

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);

This comment has been minimized.

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

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

This comment has been minimized.

Copy link
@filipesilva

filipesilva Oct 7, 2019

Author Member

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;

This comment has been minimized.

Copy link
@filipesilva

filipesilva Oct 7, 2019

Author Member

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/.

This comment has been minimized.

Copy link
@JoostK

JoostK Oct 7, 2019

Member

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)

This comment has been minimized.

Copy link
@filipesilva

filipesilva Oct 7, 2019

Author Member

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?

This comment has been minimized.

Copy link
@JoostK

JoostK Oct 7, 2019

Member

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

This comment has been minimized.

Copy link
Member 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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member Author

filipesilva commented Oct 15, 2019

@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

This comment has been minimized.

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.

@filipesilva filipesilva force-pushed the filipesilva:ts.3.7 branch from a0c0e20 to 42aef61 Oct 22, 2019
@googlebot

This comment has been minimized.

Copy link

googlebot commented Oct 22, 2019

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes and removed cla: no labels Oct 22, 2019
@mary-poppins

This comment has been minimized.

Copy link

mary-poppins commented Oct 22, 2019

@andrius-pra andrius-pra referenced this pull request Nov 10, 2019
4 of 14 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.