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: bump minimum supported TS version to 4.2.4 #5915

Merged
merged 4 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,37 @@ The latest version under the `canary` tag **(latest commit to `main`)** is:

### Supported TypeScript Version

**The version range of TypeScript currently supported by this parser is `>=3.3.1 <4.9.0`.**
**The version range of TypeScript currently supported by this parser is `>=4.2.0 <4.9.0`.**

These versions are what we test against.
Note that we mirror [DefinitelyTyped's version support window](https://github.com/DefinitelyTyped/DefinitelyTyped/#support-window) - meaning we only support versions of TypeScript less than 2 years old.

We will always endeavor to support the latest stable version of TypeScript.
Sometimes, but not always, changes in TypeScript will not require breaking changes in this project, and so we are able to support more than one version of TypeScript.
In some cases, we may even be able to support additional pre-releases (i.e. betas and release candidates) of TypeScript, but only if doing so does not require us to compromise on support for the latest stable version.
You may find that our tooling works on older TypeScript versions however we provide no guarantees and **_we will not accept issues against unsupported versions_**.

#### Supporting New TypeScript Releases

With each new TypeScript release we file an issue to track the changes in the new version. The issue should always be pinned, and you can also [find the issues by searching for issues tagged with "New TypeScript Version"](https://github.com/typescript-eslint/typescript-eslint/issues?q=is%3Aissue+label%3A%22New+TypeScript+Version%22+sort%3Acreated-desc). If the issue is open, we do not have official support yet - please be patient.

In terms of what versions we support:

- We do not support the `beta` releases.
- We _generally_ do not officially support the `rc` releases.
- We endeavor to support the latest stable TypeScript versions as soon as possible after the release.

Generally we will begin working on supporting the next release when the `rc` version is released.
Copy link
Member

Choose a reason for hiding this comment

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

Is this decision documented anywhere? Now that we have more maintainer funding & people, it'd be nice to be able to support RC releases. But that's really hard and I'm guessing still not something worth it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm all for us bumping versions and allowing RCs if we're able to - I just don't want us to set the expectation that we will support all RCs.

Sometimes releases are massive and and can take a lot of work to fully support.
Sometimes they have literally no impact for us.
Sometimes features from the beta get dropped from the RC.
Sometimes features from the RC get dropped from the full release.

There's just a lot of variability and with our limited bandwidth I don't want us to commit to anything!

Copy link
Member

Choose a reason for hiding this comment

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


#### Version Warning Logs

Note that our packages have an open `peerDependency` requirement in order to allow for experimentation on newer/beta versions of TypeScript.

If you use a non-supported version of TypeScript, the parser will log a warning to the console.
However if you use a non-supported version of TypeScript, the parser will log a warning to the console.
If you want to disable this warning, you can configure this in your `parserOptions`. See: [`@typescript-eslint/parser`](./packages/parser/) and [`@typescript-eslint/typescript-estree`](./packages/typescript-estree/).

**Please ensure that you are using a supported version before submitting any issues/bug reports.**

### Supported ESLint Version

We endeavour to support the latest stable ESLint versions as soon as possible after the release.

See the value of `eslint` declared in `@typescript-eslint/eslint-plugin`'s [package.json](./packages/eslint-plugin/package.json).

### Supported Node Version
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"tmp": "^0.2.1",
"ts-node": "^10.7.0",
"tslint": "^6.1.3",
"typescript": ">=3.3.1 <4.9.0"
"typescript": ">=4.2.4 <4.9.0"
},
"resolutions": {
"typescript": "~4.8.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import * as semver from 'semver';
import * as ts from 'typescript';

import * as util from '../util';

const is3dot9 = semver.satisfies(
ts.version,
`>= 3.9.0 || >= 3.9.1-rc || >= 3.9.0-beta`,
{
includePrerelease: true,
},
);

export default util.createRule({
name: 'no-non-null-asserted-optional-chain',
meta: {
Expand All @@ -32,16 +21,7 @@ export default util.createRule({
},
defaultOptions: [],
create(context) {
// TS3.9 made a breaking change to how non-null works with optional chains.
// Pre-3.9, `x?.y!.z` means `(x?.y).z` - i.e. it essentially scrubbed the optionality from the chain
// Post-3.9, `x?.y!.z` means `x?.y!.z` - i.e. it just asserts that the property `y` is non-null, not the result of `x?.y`.
// This means that for > 3.9, x?.y!.z is valid!
//
// NOTE: these cases are still invalid for 3.9:
// - x?.y.z!
// - (x?.y)!.z

const baseSelectors = {
return {
// non-nulling a wrapped chain will scrub all nulls introduced by the chain
// (x?.y)!
// (x?.())!
Expand Down Expand Up @@ -89,62 +69,5 @@ export default util.createRule({
});
},
};

if (is3dot9) {
return baseSelectors;
}

return {
...baseSelectors,
[[
// > :not(ChainExpression) because that case is handled by a previous selector
'MemberExpression > TSNonNullExpression.object > :not(ChainExpression)',
'CallExpression > TSNonNullExpression.callee > :not(ChainExpression)',
].join(', ')](child: TSESTree.Node): void {
// selector guarantees this assertion
const node = child.parent as TSESTree.TSNonNullExpression;

let current = child;
while (current) {
switch (current.type) {
case AST_NODE_TYPES.MemberExpression:
if (current.optional) {
// found an optional chain! stop traversing
break;
}

current = current.object;
continue;

case AST_NODE_TYPES.CallExpression:
if (current.optional) {
// found an optional chain! stop traversing
break;
}

current = current.callee;
continue;

default:
// something that's not a ChainElement, which means this is not an optional chain we want to check
return;
}
}

context.report({
node,
messageId: 'noNonNullOptionalChain',
// use a suggestion instead of a fixer, because this can obviously break type checks
suggest: [
{
messageId: 'suggestRemovingNonNull',
fix(fixer): TSESLint.RuleFix {
return fixer.removeRange([node.range[1] - 1, node.range[1]]);
},
},
],
});
},
};
},
});
30 changes: 4 additions & 26 deletions packages/eslint-plugin/src/rules/no-unnecessary-type-constraint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import * as semver from 'semver';
import * as ts from 'typescript';

import * as util from '../util';

Expand All @@ -13,20 +11,6 @@ type TypeParameterWithConstraint = MakeRequired<
'constraint'
>;

const is3dot5 = semver.satisfies(
ts.version,
`>= 3.5.0 || >= 3.5.1-rc || >= 3.5.0-beta`,
{
includePrerelease: true,
},
);

const is3dot9 =
is3dot5 &&
semver.satisfies(ts.version, `>= 3.9.0 || >= 3.9.1-rc || >= 3.9.0-beta`, {
includePrerelease: true,
});

export default util.createRule({
name: 'no-unnecessary-type-constraint',
meta: {
Expand All @@ -46,19 +30,13 @@ export default util.createRule({
},
defaultOptions: [],
create(context) {
if (!is3dot5) {
return {};
}

// In theory, we could use the type checker for more advanced constraint types...
// ...but in practice, these types are rare, and likely not worth requiring type info.
// https://github.com/typescript-eslint/typescript-eslint/pull/2516#discussion_r495731858
const unnecessaryConstraints = is3dot9
? new Map([
[AST_NODE_TYPES.TSAnyKeyword, 'any'],
[AST_NODE_TYPES.TSUnknownKeyword, 'unknown'],
])
: new Map([[AST_NODE_TYPES.TSUnknownKeyword, 'unknown']]);
const unnecessaryConstraints = new Map([
[AST_NODE_TYPES.TSAnyKeyword, 'any'],
[AST_NODE_TYPES.TSUnknownKeyword, 'unknown'],
]);

const inJsx = context.getFilename().toLowerCase().endsWith('tsx');
const source = context.getSourceCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ ruleTester.run('no-non-null-asserted-optional-chain', rule, {
'foo?.bar();',
'(foo?.bar).baz!;',
'(foo?.bar()).baz!;',
// Valid as of 3.9
'foo?.bar!.baz;',
'foo?.bar!();',
"foo?.['bar']!.baz;",
Expand Down
13 changes: 1 addition & 12 deletions packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import type {
import type { SemanticOrSyntacticError } from './semantic-or-syntactic-errors';
import type { TSESTree, TSESTreeToTSNode, TSNode } from './ts-estree';
import { AST_NODE_TYPES } from './ts-estree';
import { typescriptVersionIsAtLeast } from './version-check';

const SyntaxKind = ts.SyntaxKind;

Expand Down Expand Up @@ -2151,13 +2150,6 @@ export class Converter {
});

case SyntaxKind.NullKeyword: {
if (!typescriptVersionIsAtLeast['4.0'] && this.inTypeMode) {
// 4.0 started nesting null types inside a LiteralType node, but we still need to support pre-4.0
return this.createNode<TSESTree.TSNullKeyword>(node, {
type: AST_NODE_TYPES.TSNullKeyword,
});
}

return this.createNode<TSESTree.NullLiteral>(node, {
type: AST_NODE_TYPES.Literal,
value: null,
Expand Down Expand Up @@ -2769,10 +2761,7 @@ export class Converter {
});
}
case SyntaxKind.LiteralType: {
if (
typescriptVersionIsAtLeast['4.0'] &&
node.literal.kind === SyntaxKind.NullKeyword
) {
if (node.literal.kind === SyntaxKind.NullKeyword) {
// 4.0 started nesting null types inside a LiteralType node
// but our AST is designed around the old way of null being a keyword
return this.createNode<TSESTree.TSNullKeyword>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import debug from 'debug';
import fs from 'fs';
import semver from 'semver';
import * as ts from 'typescript';

import type { ParseSettings } from '../parseSettings';
Expand Down Expand Up @@ -249,10 +248,6 @@ function getProgramsForProjects(parseSettings: ParseSettings): ts.Program[] {
return results;
}

const isRunningNoTimeoutFix = semver.satisfies(ts.version, '>=3.9.0-beta', {
includePrerelease: true,
});

function createWatchProgram(
tsconfigPath: string,
parseSettings: ParseSettings,
Expand Down Expand Up @@ -363,34 +358,9 @@ function createWatchProgram(

// Since we don't want to asynchronously update program we want to disable timeout methods
// So any changes in the program will be delayed and updated when getProgram is called on watch
let callback: (() => void) | undefined;
if (isRunningNoTimeoutFix) {
watchCompilerHost.setTimeout = undefined;
watchCompilerHost.clearTimeout = undefined;
} else {
log('Running without timeout fix');
// But because of https://github.com/microsoft/TypeScript/pull/37308 we cannot just set it to undefined
// instead save it and call before getProgram is called
watchCompilerHost.setTimeout = (cb, _ms, ...args: unknown[]): unknown => {
callback = cb.bind(/*this*/ undefined, ...args);
return callback;
};
watchCompilerHost.clearTimeout = (): void => {
callback = undefined;
};
}
const watch = ts.createWatchProgram(watchCompilerHost);
if (!isRunningNoTimeoutFix) {
const originalGetProgram = watch.getProgram;
watch.getProgram = (): ts.BuilderProgram => {
if (callback) {
callback();
}
callback = undefined;
return originalGetProgram.call(watch);
};
}
return watch;
watchCompilerHost.setTimeout = undefined;
watchCompilerHost.clearTimeout = undefined;
return ts.createWatchProgram(watchCompilerHost);
}

function hasTSConfigChanged(tsconfigPath: CanonicalPath): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { ParseSettings } from './index';
* This needs to be kept in sync with the top-level README.md in the
* typescript-eslint monorepo
*/
const SUPPORTED_TYPESCRIPT_VERSIONS = '>=3.3.1 <4.9.0';
const SUPPORTED_TYPESCRIPT_VERSIONS = '>=4.2.4 <4.9.0';

/*
* The semver package will ignore prerelease ranges, and we don't want to explicitly document every one
Expand Down
8 changes: 3 additions & 5 deletions packages/typescript-estree/src/version-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ function semverCheck(version: string): boolean {
}

const versions = [
'3.7',
'3.8',
'3.9',
'4.0',
'4.1',
//
'4.2',
'4.3',
'4.4',
'4.5',
'4.6',
'4.7',
'4.8',
'4.9',
'5.0',
] as const;
type Versions = typeof versions extends ArrayLike<infer U> ? U : never;

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13622,7 +13622,7 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@*, "typescript@>=3.3.1 <4.9.0", "typescript@^3 || ^4", typescript@next, typescript@~4.8.3, typescript@~4.8.4:
typescript@*, "typescript@>=4.2.4 <4.9.0", "typescript@^3 || ^4", typescript@next, typescript@~4.8.3, typescript@~4.8.4:
version "4.8.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.4.tgz#c464abca159669597be5f96b8943500b238e60e6"
integrity sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==
Expand Down