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-api-guardian: overloading a function doesn't generate all of the signatures #22569

Closed
wants to merge 1 commit into from
Closed

ts-api-guardian: overloading a function doesn't generate all of the signatures #22569

wants to merge 1 commit into from

Conversation

alan-agius4
Copy link
Contributor

@alan-agius4 alan-agius4 commented Mar 3, 2018

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] 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?

Overloaded pure functions are not generated.

Issue Number: angular/ts-api-guardian#22

What is the new behavior?

Overloaded methods are generated

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

Deltas

diff --git a/tools/public_api_guard/common/common.d.ts b/tools/public_api_guard/common/common.d.ts
index 9d07132c2..cebf029d7 100644
--- a/tools/public_api_guard/common/common.d.ts
+++ b/tools/public_api_guard/common/common.d.ts
@@ -306 +306 @@ export declare class NgLocaleLocalization extends NgLocalization {
-        deprecatedPluralFn?: ((locale: string, value: string | number) => Plural) | null | undefined);
+        /** @deprecated */ deprecatedPluralFn?: ((locale: string, value: string | number) => Plural) | null | undefined);
diff --git a/tools/public_api_guard/core/core.d.ts b/tools/public_api_guard/core/core.d.ts
index 835512649..83d605e4e 100644
--- a/tools/public_api_guard/core/core.d.ts
+++ b/tools/public_api_guard/core/core.d.ts
@@ -451,0 +452 @@ export declare function inject<T>(token: Type<T> | InjectionToken<T>, notFoundVa
+export declare function inject<T>(token: Type<T> | InjectionToken<T>, notFoundValue: T | null, flags?: InjectFlags): T | null;
diff --git a/tools/public_api_guard/core/testing.d.ts b/tools/public_api_guard/core/testing.d.ts
index d4c5452ba..b5fcd428c 100644
--- a/tools/public_api_guard/core/testing.d.ts
+++ b/tools/public_api_guard/core/testing.d.ts
@@ -158,0 +159 @@ export declare function withModule(moduleDef: TestModuleMetadata): InjectSetupWr
+export declare function withModule(moduleDef: TestModuleMetadata, fn: Function): () => any;
diff --git a/tools/public_api_guard/router/testing.d.ts b/tools/public_api_guard/router/testing.d.ts
index d14731865..e7877cdc2 100644
--- a/tools/public_api_guard/router/testing.d.ts
+++ b/tools/public_api_guard/router/testing.d.ts
@@ -7,0 +8 @@ export declare function setupTestingRouter(urlSerializer: UrlSerializer, context
+export declare function setupTestingRouter(urlSerializer: UrlSerializer, contexts: ChildrenOutletContexts, location: Location, loader: NgModuleFactoryLoader, compiler: Compiler, injector: Injector, routes: Route[][], urlHandlingStrategy?: UrlHandlingStrategy): Router;

/cc @ocombe

let children: ts.Node[] = [];
if (ts.isFunctionDeclaration(node)) {
const symbol = this.typeChecker.getSymbolAtLocation(node.name);
symbol.declarations.forEach(x => children.push(...x.getChildren()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Concat is faster than push/spread if you care: dec => children = children.concat(dec.getChildren())

@alan-agius4
Copy link
Contributor Author

alan-agius4 commented Mar 3, 2018

hey @alexeagle, I am having a bit of a problem here when I am doing changes in the serializer.

Basicilly bazel test is using the local ts-api-guardian, but the gulp public-api:enforce is using the node_modules one.

Bazel fails when golden files are not updated
https://circleci.com/gh/angular/angular/34377?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link

Gulp fails when golden files are updated
https://travis-ci.org/angular/angular/jobs/348657294

So, it's impossible to have a green CI.

@alexeagle
Copy link
Contributor

@alan-agius4 that's a good point. In this case, can we just exclude core and common from the check that relies on the npm package? If not, I'll finish converting us over to the locally built one.

@alexeagle alexeagle self-assigned this Mar 5, 2018
@alan-agius4
Copy link
Contributor Author

Yes, absolutely, I pushed a change

@alexeagle alexeagle added the target: major This PR is targeted for the next major release label Mar 5, 2018
@@ -34,7 +36,8 @@ const entrypoints = [
'dist/packages-dist/platform-server/platform-server.d.ts',
'dist/packages-dist/platform-server/testing.d.ts',
'dist/packages-dist/router/router.d.ts',
'dist/packages-dist/router/testing.d.ts',
// The below has been excluded until we use the local build of API guardian
//'dist/packages-dist/router/testing.d.ts',
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't build an ng_package for router, so this isn't safe to remove...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this means we need to do it now, or else you'll have a test failure on one side or the other due to the router change in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes indeed we so need to migrate to locally built guardian now, as E2E will fail like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually have an idea of what we can do at least until everything is migrated. (Not sure how much time that involves)

My idea is that when we call gulp public-api:enforce we can a pre-gulp task invoking

bazel run //:install
bazel build //tools/ts-api-guardian:lib

And than from the gulp tasks, rather than requiring the node_module we require the local guardian.

@@ -215,7 +215,14 @@ class ResolvedDeclarationEmitter {
}
}

let children = node.getChildren();
let children: ts.Node[] = [];
if (ts.isFunctionDeclaration(node)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used ts.isFunctionDeclaration instead of node.kind because this is a type guard.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd put this kind of thing as a comment in the source code - many people will read that later, no one will see this thread

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@alexeagle alexeagle added the area: build & ci Related the build and CI infrastructure of the project label Mar 5, 2018
@alexeagle
Copy link
Contributor

let's land #22628 first to clean this up. I think you need router to be tested with the local ts-api-guardian.

@alexeagle
Copy link
Contributor

okay that's @alan-agius4 that's merged, can you re-base and green this up? thanks!!

@ngbot
Copy link

ngbot bot commented Mar 7, 2018

Hi @alan-agius4! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

@alan-agius4
Copy link
Contributor Author

alan-agius4 commented Mar 7, 2018 via email

@alan-agius4
Copy link
Contributor Author

@alexeagle it’s green 🎉

Copy link
Contributor

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

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

Awesome thank you!!

@@ -215,7 +215,14 @@ class ResolvedDeclarationEmitter {
}
}

let children = node.getChildren();
let children: ts.Node[] = [];
if (ts.isFunctionDeclaration(node)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd put this kind of thing as a comment in the source code - many people will read that later, no one will see this thread

Copy link
Contributor

@IgorMinar IgorMinar left a comment

Choose a reason for hiding this comment

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

Thank you so much for this fix!

@IgorMinar IgorMinar added the action: merge The PR is ready for merge by the caretaker label Mar 9, 2018
@alan-agius4
Copy link
Contributor Author

Welcome, glad to help.

@kara kara closed this in e8326e6 Mar 9, 2018
@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 Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: build & ci Related the build and CI infrastructure of the project cla: yes target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants