Skip to content

Commit 2399d58

Browse files
committed
Improve TupleBase docs and backward compatibility
1 parent 4385444 commit 2399d58

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4997,7 +4997,7 @@ namespace ts {
49974997
function getBaseTypes(type: InterfaceType): BaseType[] {
49984998
if (!type.resolvedBaseTypes) {
49994999
if (type.objectFlags & ObjectFlags.Tuple) {
5000-
type.resolvedBaseTypes = [createTypeFromGenericGlobalType(globalTupleBaseType, [getUnionType(type.typeParameters)])];
5000+
type.resolvedBaseTypes = [createTypeFromGenericGlobalType(globalTupleBaseType || globalArrayType, [getUnionType(type.typeParameters)])];
50015001
}
50025002
else if (type.symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
50035003
if (type.symbol.flags & SymbolFlags.Class) {
@@ -24511,8 +24511,8 @@ namespace ts {
2451124511
autoArrayType = createArrayType(autoType);
2451224512

2451324513
// TODO: ReadonlyArray and TupleBase should always be available, but haven't been required previously
24514-
globalReadonlyArrayType = <GenericType>getGlobalType("ReadonlyArray" as __String, /*arity*/ 1, /*reportErrors*/ true);
24515-
globalTupleBaseType = <GenericType>getGlobalType("TupleBase" as __String, /*arity*/ 1, /*reportErrors*/ true);
24514+
globalReadonlyArrayType = <GenericType>getGlobalTypeOrUndefined("ReadonlyArray" as __String, /*arity*/ 1);
24515+
globalTupleBaseType = <GenericType>getGlobalTypeOrUndefined("TupleBase" as __String, /*arity*/ 1);
2451624516
anyReadonlyArrayType = globalReadonlyArrayType ? createTypeFromGenericGlobalType(globalReadonlyArrayType, [anyType]) : anyArrayType;
2451724517
globalThisType = <GenericType>getGlobalTypeOrUndefined("ThisType" as __String, /*arity*/ 1);
2451824518
}

src/lib/es5.d.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,15 +1241,20 @@ interface ArrayConstructor {
12411241
declare const Array: ArrayConstructor;
12421242

12431243
interface TupleBase<T> extends Array<T> {
1244-
// TODO: Add jsdoc here warning not to call this
1245-
push(...items: never[]): never;
1246-
pop(): never | undefined;
1247-
reverse(): never[];
1248-
sort(compareFn?: (a: never, b: never) => number): never;
1249-
shift(): never | undefined;
1250-
unshift(...items: never[]): never;
1251-
splice(start: number, deleteCount?: number): never[];
1252-
splice(start: number, deleteCount: number, ...items: never[]): never[];
1244+
/** Mutation is not allowed on tuples. Do not use this method. */
1245+
push: never;
1246+
/** Mutation is not allowed on tuples. Do not use this method. */
1247+
pop: never;
1248+
/** Mutation is not allowed on tuples. Do not use this method. */
1249+
reverse: never;
1250+
/** Mutation is not allowed on tuples. Do not use this method. */
1251+
sort: never;
1252+
/** Mutation is not allowed on tuples. Do not use this method. */
1253+
shift: never;
1254+
/** Mutation is not allowed on tuples. Do not use this method. */
1255+
unshift: never;
1256+
/** Mutation is not allowed on tuples. Do not use this method. */
1257+
splice: never;
12531258
}
12541259

12551260
interface TypedPropertyDescriptor<T> {

0 commit comments

Comments
 (0)