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

feat(build): add more TypeScript "strict" checks #2704

Merged
merged 1 commit into from
Apr 17, 2019

Conversation

bajtos
Copy link
Member

@bajtos bajtos commented Apr 8, 2019

Enable all "strict" checks with the exception of strictPropertyInitialization which would require significant changes.

The following additional checks are added:

  • noImplicitThis
  • alwaysStrict
  • strictFunctionTypes

In the future, any checks added to TypeScript "strict" mode will be automatically enabled for LoopBack projects too.

See also TypeScript Compiler Options

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

@bajtos bajtos added the Internal Tooling Issues related to our tooling and monorepo infrastructore label Apr 8, 2019
@bajtos bajtos self-assigned this Apr 8, 2019
@bajtos bajtos requested review from raymondfeng and a team April 8, 2019 11:44
@raymondfeng
Copy link
Contributor

Now #2711 is landed, please rebase against latest master.

@bajtos bajtos force-pushed the feat/tsc-strict-checks branch from 234ec10 to af016a4 Compare April 11, 2019 09:48
@bajtos
Copy link
Member Author

bajtos commented Apr 11, 2019

Now #2711 is landed, please rebase against latest master.

Done.

I have also changed the way how I address the problem with BindingFilter<T> vs. BindingFilter<unknown>, see 90117fa

@raymondfeng LGTY now?

@bajtos bajtos force-pushed the feat/tsc-strict-checks branch 2 times, most recently from bfffe47 to a18b41b Compare April 11, 2019 10:15
* We learned about this problem after enabling TypeScript's `strictFunctionTypes`
* check, but decided to preserve `ValueType` argument for backwards compatibility.
*
* TODO(semver-major): remove ValueType template argument.
Copy link
Contributor

Choose a reason for hiding this comment

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

See #2728. The ValueType is used internally with a default. Applications or extensions may define their own filter functions and mostly won't cast it to BindingFilter<...>. I don't think we have to release a new major.

@raymondfeng
Copy link
Contributor

Is there a possibility that this change will break existing applications?

@@ -161,10 +161,10 @@ export class ContextView<T = unknown> extends EventEmitter
*/
export function createViewGetter<T = unknown>(
ctx: Context,
bindingFilter: BindingFilter<T>,
bindingFilter: BindingFilter,
Copy link
Member Author

Choose a reason for hiding this comment

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

Before this change, it was possible to infer T in createViewGetter from bindingFilter type.

const filter: BindingFilter<MyValue> = b => true;
const getter = createViewGetter(ctx, filter);
// ^^^ getter is of type Getter<MyValue[]>

With this change in place, users have to explicitly specify the getter type, otherwise they end up with unknown.

const getter = createViewGetter(ctx, filter);
// ^^^ getter is of type Getter<unknown[]>

const getter = createViewGetter<MyValue>(ctx, filter);
// ^^^ getter is of type Getter<MyValue[]>

session?: ResolutionSession,
): Getter<T[]> {
const view = new ContextView(ctx, bindingFilter);
const view = new ContextView<T>(ctx, bindingFilter);
Copy link
Member Author

Choose a reason for hiding this comment

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

Similarly here. Before this change, it was possible to infer T of ContextView from bindingFilter type. After this change, new ContextView(...) always treats T as unknown.

@bajtos
Copy link
Member Author

bajtos commented Apr 12, 2019

Is there a possibility that this change will break existing applications?

Good question, see my two comments above.

@bajtos
Copy link
Member Author

bajtos commented Apr 12, 2019

Also any project using @loopback/build and our shared tsconfig may start failing to compile if they are not violating any of the newly enabled checks.

I don't consider this as a change that would require semver-major, because this situation happens regularly with new semver-minor releases of TypeScript. TypeScript releases a new version, e.g. 3.4, consumers upgrade to this new version (because @loopback/build uses ^3.3.0 as the dependency spec) automatically, and because the new version of compiler is rejecting code that was accepted by the old version, build suddenly breaks. I am arguing that build broken by a new "strict" rule enabled by @loopback/build is conceptually the same as when the build is broken by a new version of tsc.

@bajtos
Copy link
Member Author

bajtos commented Apr 12, 2019

I have extracted the first two commits to get them landed faster: #2733

@bajtos bajtos force-pushed the feat/tsc-strict-checks branch 2 times, most recently from ed788bf to e37e5f4 Compare April 16, 2019 08:03
Enable all "strict" checks with the exception of
`strictPropertyInitialization` which would require significant changes.

The following additional checks are added:

- noImplicitThis
- alwaysStrict
- strictFunctionTypes

In the future, any checks added to TypeScript "strict" mode will be
automatically enabled for LoopBack projects too.
@bajtos bajtos force-pushed the feat/tsc-strict-checks branch from e37e5f4 to 70af431 Compare April 16, 2019 08:05
@bajtos
Copy link
Member Author

bajtos commented Apr 16, 2019

@raymondfeng I have rebased the pull request on top of the latest master, it's ready for final review & landing. LGTY?

@bajtos bajtos requested a review from raymondfeng April 16, 2019 08:06
@raymondfeng raymondfeng merged commit 866aa2f into master Apr 17, 2019
@raymondfeng raymondfeng deleted the feat/tsc-strict-checks branch April 17, 2019 16:33
@raymondfeng
Copy link
Contributor

@bajtos I landed for you to reduce the backlog of PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internal Tooling Issues related to our tooling and monorepo infrastructore
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants