Skip to content

Commit

Permalink
Enable strictPropertyInitialization and noImplicitThis checks in tsco…
Browse files Browse the repository at this point in the history
…nfig (#1814)

* Enable strictPropertyInitialzation

* Enable noImpictThis checks

* Add changelogs
  • Loading branch information
BPScott committed Apr 5, 2021
1 parent 8aeccd3 commit 13188ca
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 18 deletions.
2 changes: 0 additions & 2 deletions config/typescript/tsconfig.base.json
Expand Up @@ -7,9 +7,7 @@
// the time before we wanted strict mode
"strictBindCallApply": false,
"strictFunctionTypes": false,
"strictPropertyInitialization": false,
"noImplicitAny": false,
"noImplicitThis": false,
"typeRoots": ["../../node_modules/@types"]
}
}
6 changes: 6 additions & 0 deletions packages/address/CHANGELOG.md
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Updated types within loader so it passes TypeScript's "noImplicitThis" checks. [#1814](https://github.com/Shopify/quilt/pull/1814)

## [2.10.3] - 2021-03-03

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion packages/address/src/loader.ts
Expand Up @@ -76,7 +76,7 @@ interface Cache {
[key: string]: Promise<any>;
}

function memoizeAsync(asyncFunction: AsyncFunc) {
function memoizeAsync(this: unknown, asyncFunction: AsyncFunc) {
const cache: Cache = {};

return (...args: any[]) => {
Expand Down
6 changes: 6 additions & 0 deletions packages/function-enhancers/CHANGELOG.md
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Updated types within memoize so it passes TypeScript's "noImplicitThis" checks. [#1814](https://github.com/Shopify/quilt/pull/1814)

## [1.1.2] - 2021-03-03

### Fixed
Expand Down
7 changes: 3 additions & 4 deletions packages/function-enhancers/src/memoize.ts
Expand Up @@ -6,10 +6,9 @@ interface MemoizeMap<T, U> {

export const MAX_MAP_ENTRIES = 50;

export default function memoize<Method extends (...args: any[]) => any>(
method: Method,
resolver?: (...args: Parameters<Method>) => any,
): Method {
export default function memoize<
Method extends (this: unknown, ...args: any[]) => any
>(method: Method, resolver?: (...args: Parameters<Method>) => any): Method {
const weakMapCache = new WeakMap();
const mapCache = new Map();
const mapKeys: any[] = [];
Expand Down
6 changes: 6 additions & 0 deletions packages/jest-dom-mocks/CHANGELOG.md
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Updated match-media mock so it passes TypeScript's "strictPropertyInitialization" checks. [#1814](https://github.com/Shopify/quilt/pull/1814)

## [2.11.2] - 2021-03-03

### Fixed
Expand Down
15 changes: 6 additions & 9 deletions packages/jest-dom-mocks/src/match-media.ts
Expand Up @@ -3,35 +3,32 @@ export interface MediaMatching {
}

export default class MatchMedia {
originalMatchMedia: (mediaQuery: string) => MediaQueryList;
private isUsingMockMatchMedia = false;
originalMatchMedia: ((mediaQuery: string) => MediaQueryList) | null = null;

mock(media: MediaMatching = defaultMatcher) {
if (this.isUsingMockMatchMedia) {
if (this.originalMatchMedia !== null) {
throw new Error(
'You tried to mock window.matchMedia when it was already mocked.',
);
}

this.originalMatchMedia = window.matchMedia;
this.isUsingMockMatchMedia = true;

this.setMedia(media);
}

restore() {
if (!this.isUsingMockMatchMedia) {
if (this.originalMatchMedia === null) {
throw new Error(
'You tried to restore window.matchMedia when it was already restored.',
);
}

window.matchMedia = this.originalMatchMedia;
this.isUsingMockMatchMedia = false;
this.originalMatchMedia = null;
}

isMocked() {
return this.isUsingMockMatchMedia;
return this.originalMatchMedia !== null;
}

setMedia(media: MediaMatching = defaultMatcher) {
Expand All @@ -40,7 +37,7 @@ export default class MatchMedia {
}

private ensureMatchMediaIsMocked() {
if (!this.isUsingMockMatchMedia) {
if (this.originalMatchMedia === null) {
throw new Error(
'You must call matchMedia.mock() before interacting with the mock matchMedia.',
);
Expand Down
6 changes: 6 additions & 0 deletions packages/polyfills/CHANGELOG.md
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Updated types within fetch.node so it passes TypeScript's "noImplicitThis" checks. [#1814](https://github.com/Shopify/quilt/pull/1814)

## [1.3.2] - 2021-03-03

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion packages/polyfills/src/fetch.node.ts
Expand Up @@ -4,7 +4,7 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const nodeFetch = require('node-fetch');

function wrappedFetch(url: string | Request, options) {
function wrappedFetch(this: unknown, url: string | Request, options) {
if (typeof url !== 'string') {
return nodeFetch.call(this, url, options);
}
Expand Down
6 changes: 5 additions & 1 deletion packages/react-i18n/CHANGELOG.md
Expand Up @@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

<!-- ## [Unreleased] -->
## [Unreleased]

### Changed

- Error when you don't pass a filename to babel when using the babel plugin. Updated types within babel-plugin so it passes TypeScript's "noImplicitThis" checks. [#1814](https://github.com/Shopify/quilt/pull/1814)

## [5.3.1] - 2021-03-23

Expand Down
8 changes: 8 additions & 0 deletions packages/react-i18n/src/babel-plugin/index.ts
Expand Up @@ -3,6 +3,7 @@ import path from 'path';
import glob from 'glob';
import stringHash from 'string-hash';
import {camelCase} from 'change-case';
import type {BabelFile} from '@babel/core';
import {TemplateBuilder} from '@babel/template';
import Types from '@babel/types';
import {Node, NodePath} from '@babel/traverse';
Expand Down Expand Up @@ -80,6 +81,7 @@ export default function injectWithI18nArguments({
state.program = nodePath;
},
ImportDeclaration(
this: {file: BabelFile},
nodePath: NodePath<Types.ImportDeclaration>,
state: State,
) {
Expand Down Expand Up @@ -115,6 +117,12 @@ export default function injectWithI18nArguments({
).name;
const {filename} = this.file.opts;

if (typeof filename !== 'string') {
throw new Error(
`You attempted to run the react-i18n plugin on code without specifying an input filename. A filename is required to sucessfully inject translation information.`,
);
}

if (mode === 'from-dictionary-index') {
const translationArrayID = '__shopify__i18n_translations';
addI18nArguments({
Expand Down

0 comments on commit 13188ca

Please sign in to comment.