Skip to content

Commit a6f3eb7

Browse files
committed
Respect //@ts-nocheck in TS files
1 parent f9cc374 commit a6f3eb7

File tree

5 files changed

+116
-1
lines changed

5 files changed

+116
-1
lines changed

src/compiler/program.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1691,8 +1691,9 @@ namespace ts {
16911691
Debug.assert(!!sourceFile.bindDiagnostics);
16921692

16931693
const isCheckJs = isCheckJsEnabledForFile(sourceFile, options);
1694+
const isTsNoCheck = !!sourceFile.checkJsDirective && sourceFile.checkJsDirective.enabled === false;
16941695
// By default, only type-check .ts, .tsx, 'Deferred' and 'External' files (external files are added by plugins)
1695-
const includeBindAndCheckDiagnostics = sourceFile.scriptKind === ScriptKind.TS || sourceFile.scriptKind === ScriptKind.TSX ||
1696+
const includeBindAndCheckDiagnostics = !isTsNoCheck && sourceFile.scriptKind === ScriptKind.TS || sourceFile.scriptKind === ScriptKind.TSX ||
16961697
sourceFile.scriptKind === ScriptKind.External || isCheckJs || sourceFile.scriptKind === ScriptKind.Deferred;
16971698
const bindDiagnostics: readonly Diagnostic[] = includeBindAndCheckDiagnostics ? sourceFile.bindDiagnostics : emptyArray;
16981699
const checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : emptyArray;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//// [file.ts]
2+
// @ts-nocheck
3+
4+
export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment
5+
6+
export interface Aleph {
7+
q: number;
8+
}
9+
10+
export class Bet implements Aleph {
11+
q: string = "lol" // And so will this implements error
12+
}
13+
14+
15+
//// [file.js]
16+
"use strict";
17+
// @ts-nocheck
18+
exports.__esModule = true;
19+
exports.a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment
20+
var Bet = /** @class */ (function () {
21+
function Bet() {
22+
this.q = "lol"; // And so will this implements error
23+
}
24+
return Bet;
25+
}());
26+
exports.Bet = Bet;
27+
28+
29+
//// [file.d.ts]
30+
export declare const a: any;
31+
export interface Aleph {
32+
q: number;
33+
}
34+
export declare class Bet implements Aleph {
35+
q: string;
36+
}
37+
38+
39+
//// [DtsFileErrors]
40+
41+
42+
tests/cases/conformance/jsdoc/file.d.ts(6,5): error TS2416: Property 'q' in type 'Bet' is not assignable to the same property in base type 'Aleph'.
43+
Type 'string' is not assignable to type 'number'.
44+
45+
46+
==== tests/cases/conformance/jsdoc/file.d.ts (1 errors) ====
47+
export declare const a: any;
48+
export interface Aleph {
49+
q: number;
50+
}
51+
export declare class Bet implements Aleph {
52+
q: string;
53+
~
54+
!!! error TS2416: Property 'q' in type 'Bet' is not assignable to the same property in base type 'Aleph'.
55+
!!! error TS2416: Type 'string' is not assignable to type 'number'.
56+
}
57+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
=== tests/cases/conformance/jsdoc/file.ts ===
2+
// @ts-nocheck
3+
4+
export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment
5+
>a : Symbol(a, Decl(file.ts, 2, 12))
6+
7+
export interface Aleph {
8+
>Aleph : Symbol(Aleph, Decl(file.ts, 2, 24))
9+
10+
q: number;
11+
>q : Symbol(Aleph.q, Decl(file.ts, 4, 24))
12+
}
13+
14+
export class Bet implements Aleph {
15+
>Bet : Symbol(Bet, Decl(file.ts, 6, 1))
16+
>Aleph : Symbol(Aleph, Decl(file.ts, 2, 24))
17+
18+
q: string = "lol" // And so will this implements error
19+
>q : Symbol(Bet.q, Decl(file.ts, 8, 35))
20+
}
21+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/conformance/jsdoc/file.ts ===
2+
// @ts-nocheck
3+
4+
export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment
5+
>a : any
6+
>1 + {} : any
7+
>1 : 1
8+
>{} : {}
9+
10+
export interface Aleph {
11+
q: number;
12+
>q : number
13+
}
14+
15+
export class Bet implements Aleph {
16+
>Bet : Bet
17+
18+
q: string = "lol" // And so will this implements error
19+
>q : string
20+
>"lol" : "lol"
21+
}
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @declaration: true
2+
// @filename: file.ts
3+
4+
// @ts-nocheck
5+
6+
export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment
7+
8+
export interface Aleph {
9+
q: number;
10+
}
11+
12+
export class Bet implements Aleph {
13+
q: string = "lol" // And so will this implements error
14+
}

0 commit comments

Comments
 (0)