Skip to content

Commit af90e70

Browse files
authored
feat(49903): omit declare on type declarations (#49925)
1 parent b94b299 commit af90e70

File tree

171 files changed

+1857
-1841
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+1857
-1841
lines changed

src/compiler/transformers/declarations.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,14 +1217,18 @@ namespace ts {
12171217

12181218
const previousNeedsDeclare = needsDeclare;
12191219
switch (input.kind) {
1220-
case SyntaxKind.TypeAliasDeclaration: // Type aliases get `declare`d if need be (for legacy support), but that's all
1221-
return cleanup(factory.updateTypeAliasDeclaration(
1220+
case SyntaxKind.TypeAliasDeclaration: {
1221+
needsDeclare = false;
1222+
const clean = cleanup(factory.updateTypeAliasDeclaration(
12221223
input,
12231224
ensureModifiers(input),
12241225
input.name,
12251226
visitNodes(input.typeParameters, visitDeclarationSubtree, isTypeParameterDeclaration),
12261227
visitNode(input.type, visitDeclarationSubtree, isTypeNode)
12271228
));
1229+
needsDeclare = previousNeedsDeclare;
1230+
return clean;
1231+
}
12281232
case SyntaxKind.InterfaceDeclaration: {
12291233
return cleanup(factory.updateInterfaceDeclaration(
12301234
input,

tests/baselines/reference/DeclarationErrorsNoEmitOnError.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ exports.__esModule = true;
1010

1111

1212
//// [DeclarationErrorsNoEmitOnError.d.ts]
13-
declare type T = {
13+
type T = {
1414
x: number;
1515
};
1616
export interface I {

tests/baselines/reference/anonClassDeclarationEmitIsAnon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export declare function wrapClass(param: any): {
122122
foo(): any;
123123
};
124124
};
125-
export declare type Constructor<T = {}> = new (...args: any[]) => T;
125+
export type Constructor<T = {}> = new (...args: any[]) => T;
126126
export declare function Timestamped<TBase extends Constructor>(Base: TBase): {
127127
new (...args: any[]): {
128128
timestamp: number;

tests/baselines/reference/caseInsensitiveFileSystemWithCapsImportTypeDeclarations.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ exports.Broken = Broken;
4848

4949

5050
//// [types.d.ts]
51-
export declare type Merge<T, U> = T & U;
51+
export type Merge<T, U> = T & U;
5252
//// [type-a.d.ts]
53-
export declare type TypeA = {
53+
export type TypeA = {
5454
a: string;
5555
};
5656
//// [type-b.d.ts]
5757
import { Merge } from './types';
5858
import { TypeA } from './type-a';
59-
export declare type TypeB = Merge<TypeA, {
59+
export type TypeB = Merge<TypeA, {
6060
b: string;
6161
}>;
6262
//// [index.d.ts]

tests/baselines/reference/circularAccessorAnnotations.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ declare const c3: {
4141
get foo(): string;
4242
set foo(value: typeof c3.foo);
4343
};
44-
declare type T1 = {
44+
type T1 = {
4545
get foo(): T1["foo"];
4646
};
47-
declare type T2 = {
47+
type T2 = {
4848
set foo(value: T2["foo"]);
4949
};
50-
declare type T3 = {
50+
type T3 = {
5151
get foo(): string;
5252
set foo(value: T3["foo"]);
5353
};

tests/baselines/reference/circularBaseTypes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ function f(m) {
2020

2121

2222
//// [circularBaseTypes.d.ts]
23-
declare type M<T> = {
23+
type M<T> = {
2424
value: T;
2525
};
2626
interface M2 extends M<M3> {
2727
}
28-
declare type M3 = M2[keyof M2];
28+
type M3 = M2[keyof M2];
2929
declare function f(m: M3): any;

tests/baselines/reference/circularIndexedAccessErrors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ function foo() {
5656

5757

5858
//// [circularIndexedAccessErrors.d.ts]
59-
declare type T1 = {
59+
type T1 = {
6060
x: T1["x"];
6161
};
62-
declare type T2<K extends "x" | "y"> = {
62+
type T2<K extends "x" | "y"> = {
6363
x: T2<K>[K];
6464
y: number;
6565
};

tests/baselines/reference/coAndContraVariantInferences.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ call(actionB, printFn);
5050

5151

5252
//// [coAndContraVariantInferences.d.ts]
53-
declare type A = {
53+
type A = {
5454
kind: 'a';
5555
};
56-
declare type B = {
56+
type B = {
5757
kind: 'b';
5858
};
5959
declare const a: A;

0 commit comments

Comments
 (0)