mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Accepted baselines.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
tests/cases/conformance/functions/overloadsWithTypePredicates01.ts(35,10): error TS2394: Overload signature is not compatible with function implementation.
|
||||
|
||||
|
||||
==== tests/cases/conformance/functions/overloadsWithTypePredicates01.ts (1 errors) ====
|
||||
|
||||
/**
|
||||
* A makeshift string enum.
|
||||
*/
|
||||
namespace EventType {
|
||||
export type Click = string & { _fooTag: any };
|
||||
export const Click = <Click>"Click";
|
||||
|
||||
export type KeyDown = string & { _barTag: any };
|
||||
export const KeyDown = <KeyDown>"KeyDown";
|
||||
}
|
||||
|
||||
/**
|
||||
* The all-encompassing type for our makeshift enum.
|
||||
*/
|
||||
type EventType = EventType.Click
|
||||
| EventType.KeyDown;
|
||||
|
||||
|
||||
interface BaseEvent {
|
||||
type: EventType;
|
||||
}
|
||||
|
||||
interface ClickEvent extends BaseEvent {
|
||||
type: EventType.Click;
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
interface KeyDownEvent extends BaseEvent {
|
||||
type: EventType.KeyDown;
|
||||
keyCode: number;
|
||||
}
|
||||
|
||||
function isActionType(action: BaseEvent, type: EventType.Click): action is ClickEvent;
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2394: Overload signature is not compatible with function implementation.
|
||||
function isActionType(action: BaseEvent, type: EventType.KeyDown): action is KeyDownEvent;
|
||||
function isActionType(action: BaseEvent, type: EventType): action is BaseEvent;
|
||||
function isActionType(action: BaseEvent, type: EventType) {
|
||||
return action.type === type;
|
||||
}
|
||||
|
||||
let handleAction = (action: BaseEvent) => {
|
||||
if (isActionType(action, EventType.Click)) {
|
||||
let foo = action.x;
|
||||
let bar = action.y;
|
||||
}
|
||||
|
||||
if (isActionType(action, EventType.KeyDown)) {
|
||||
let bar = action.keyCode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
//// [overloadsWithTypePredicates01.ts]
|
||||
|
||||
/**
|
||||
* A makeshift string enum.
|
||||
*/
|
||||
namespace EventType {
|
||||
export type Click = string & { _fooTag: any };
|
||||
export const Click = <Click>"Click";
|
||||
|
||||
export type KeyDown = string & { _barTag: any };
|
||||
export const KeyDown = <KeyDown>"KeyDown";
|
||||
}
|
||||
|
||||
/**
|
||||
* The all-encompassing type for our makeshift enum.
|
||||
*/
|
||||
type EventType = EventType.Click
|
||||
| EventType.KeyDown;
|
||||
|
||||
|
||||
interface BaseEvent {
|
||||
type: EventType;
|
||||
}
|
||||
|
||||
interface ClickEvent extends BaseEvent {
|
||||
type: EventType.Click;
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
interface KeyDownEvent extends BaseEvent {
|
||||
type: EventType.KeyDown;
|
||||
keyCode: number;
|
||||
}
|
||||
|
||||
function isActionType(action: BaseEvent, type: EventType.Click): action is ClickEvent;
|
||||
function isActionType(action: BaseEvent, type: EventType.KeyDown): action is KeyDownEvent;
|
||||
function isActionType(action: BaseEvent, type: EventType): action is BaseEvent;
|
||||
function isActionType(action: BaseEvent, type: EventType) {
|
||||
return action.type === type;
|
||||
}
|
||||
|
||||
let handleAction = (action: BaseEvent) => {
|
||||
if (isActionType(action, EventType.Click)) {
|
||||
let foo = action.x;
|
||||
let bar = action.y;
|
||||
}
|
||||
|
||||
if (isActionType(action, EventType.KeyDown)) {
|
||||
let bar = action.keyCode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [overloadsWithTypePredicates01.js]
|
||||
/**
|
||||
* A makeshift string enum.
|
||||
*/
|
||||
var EventType;
|
||||
(function (EventType) {
|
||||
EventType.Click = "Click";
|
||||
EventType.KeyDown = "KeyDown";
|
||||
})(EventType || (EventType = {}));
|
||||
function isActionType(action, type) {
|
||||
return action.type === type;
|
||||
}
|
||||
var handleAction = function (action) {
|
||||
if (isActionType(action, EventType.Click)) {
|
||||
var foo = action.x;
|
||||
var bar = action.y;
|
||||
}
|
||||
if (isActionType(action, EventType.KeyDown)) {
|
||||
var bar = action.keyCode;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//// [overloadsWithTypePredicates01.d.ts]
|
||||
/**
|
||||
* A makeshift string enum.
|
||||
*/
|
||||
declare namespace EventType {
|
||||
type Click = string & {
|
||||
_fooTag: any;
|
||||
};
|
||||
const Click: string & {
|
||||
_fooTag: any;
|
||||
};
|
||||
type KeyDown = string & {
|
||||
_barTag: any;
|
||||
};
|
||||
const KeyDown: string & {
|
||||
_barTag: any;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* The all-encompassing type for our makeshift enum.
|
||||
*/
|
||||
declare type EventType = EventType.Click | EventType.KeyDown;
|
||||
interface BaseEvent {
|
||||
type: EventType;
|
||||
}
|
||||
interface ClickEvent extends BaseEvent {
|
||||
type: EventType.Click;
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
interface KeyDownEvent extends BaseEvent {
|
||||
type: EventType.KeyDown;
|
||||
keyCode: number;
|
||||
}
|
||||
declare function isActionType(action: BaseEvent, type: EventType.Click): action is ClickEvent;
|
||||
declare function isActionType(action: BaseEvent, type: EventType.KeyDown): action is KeyDownEvent;
|
||||
declare function isActionType(action: BaseEvent, type: EventType): action is BaseEvent;
|
||||
declare let handleAction: (action: BaseEvent) => void;
|
||||
@@ -0,0 +1,57 @@
|
||||
tests/cases/conformance/functions/overloadsWithTypePredicates02.ts(22,10): error TS2394: Overload signature is not compatible with function implementation.
|
||||
|
||||
|
||||
==== tests/cases/conformance/functions/overloadsWithTypePredicates02.ts (1 errors) ====
|
||||
|
||||
interface Nil {
|
||||
}
|
||||
|
||||
interface Cons<T> {
|
||||
value: T;
|
||||
next: List<T>;
|
||||
}
|
||||
|
||||
type List<T> = Cons<T> | Nil;
|
||||
const nil: Nil = {};
|
||||
function cons<T>(value: T, next: List<T>) {
|
||||
return { value, next };
|
||||
}
|
||||
|
||||
function hasElements<T>(list: Cons<T>): list is Cons<T>;
|
||||
function hasElements<T>(list: List<T>): list is Cons<T>;
|
||||
function hasElements<T>(list: List<T>): list is Cons<T> {
|
||||
return !!(list as Cons<T>).next;
|
||||
}
|
||||
|
||||
function isEmpty(list: Nil): list is Nil;
|
||||
~~~~~~~
|
||||
!!! error TS2394: Overload signature is not compatible with function implementation.
|
||||
function isEmpty<T>(list: List<T>): list is Nil;
|
||||
function isEmpty<T>(list: List<T>): boolean {
|
||||
return !isEmpty(list);
|
||||
}
|
||||
|
||||
let listA = cons(1, cons(2, cons(3, nil)));
|
||||
let listB = nil;
|
||||
let listC: List<number> = listA || listB;
|
||||
|
||||
if (isEmpty(listA)) {
|
||||
let a = listA;
|
||||
}
|
||||
else {
|
||||
let a = listA;
|
||||
}
|
||||
|
||||
if (hasElements(listC)) {
|
||||
let { value } = listC;
|
||||
}
|
||||
else {
|
||||
let myNil: Nil = listC;
|
||||
}
|
||||
|
||||
if (hasElements(listB)) {
|
||||
let somehowCons: Cons<any> = listB;
|
||||
}
|
||||
else {
|
||||
let myNil: Nil = listB;
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
//// [overloadsWithTypePredicates02.ts]
|
||||
|
||||
interface Nil {
|
||||
}
|
||||
|
||||
interface Cons<T> {
|
||||
value: T;
|
||||
next: List<T>;
|
||||
}
|
||||
|
||||
type List<T> = Cons<T> | Nil;
|
||||
const nil: Nil = {};
|
||||
function cons<T>(value: T, next: List<T>) {
|
||||
return { value, next };
|
||||
}
|
||||
|
||||
function hasElements<T>(list: Cons<T>): list is Cons<T>;
|
||||
function hasElements<T>(list: List<T>): list is Cons<T>;
|
||||
function hasElements<T>(list: List<T>): list is Cons<T> {
|
||||
return !!(list as Cons<T>).next;
|
||||
}
|
||||
|
||||
function isEmpty(list: Nil): list is Nil;
|
||||
function isEmpty<T>(list: List<T>): list is Nil;
|
||||
function isEmpty<T>(list: List<T>): boolean {
|
||||
return !isEmpty(list);
|
||||
}
|
||||
|
||||
let listA = cons(1, cons(2, cons(3, nil)));
|
||||
let listB = nil;
|
||||
let listC: List<number> = listA || listB;
|
||||
|
||||
if (isEmpty(listA)) {
|
||||
let a = listA;
|
||||
}
|
||||
else {
|
||||
let a = listA;
|
||||
}
|
||||
|
||||
if (hasElements(listC)) {
|
||||
let { value } = listC;
|
||||
}
|
||||
else {
|
||||
let myNil: Nil = listC;
|
||||
}
|
||||
|
||||
if (hasElements(listB)) {
|
||||
let somehowCons: Cons<any> = listB;
|
||||
}
|
||||
else {
|
||||
let myNil: Nil = listB;
|
||||
}
|
||||
|
||||
//// [overloadsWithTypePredicates02.js]
|
||||
var nil = {};
|
||||
function cons(value, next) {
|
||||
return { value: value, next: next };
|
||||
}
|
||||
function hasElements(list) {
|
||||
return !!list.next;
|
||||
}
|
||||
function isEmpty(list) {
|
||||
return !isEmpty(list);
|
||||
}
|
||||
var listA = cons(1, cons(2, cons(3, nil)));
|
||||
var listB = nil;
|
||||
var listC = listA || listB;
|
||||
if (isEmpty(listA)) {
|
||||
var a = listA;
|
||||
}
|
||||
else {
|
||||
var a = listA;
|
||||
}
|
||||
if (hasElements(listC)) {
|
||||
var value = listC.value;
|
||||
}
|
||||
else {
|
||||
var myNil = listC;
|
||||
}
|
||||
if (hasElements(listB)) {
|
||||
var somehowCons = listB;
|
||||
}
|
||||
else {
|
||||
var myNil = listB;
|
||||
}
|
||||
|
||||
|
||||
//// [overloadsWithTypePredicates02.d.ts]
|
||||
interface Nil {
|
||||
}
|
||||
interface Cons<T> {
|
||||
value: T;
|
||||
next: List<T>;
|
||||
}
|
||||
declare type List<T> = Cons<T> | Nil;
|
||||
declare const nil: Nil;
|
||||
declare function cons<T>(value: T, next: List<T>): {
|
||||
value: T;
|
||||
next: Cons<T> | Nil;
|
||||
};
|
||||
declare function hasElements<T>(list: Cons<T>): list is Cons<T>;
|
||||
declare function hasElements<T>(list: List<T>): list is Cons<T>;
|
||||
declare function isEmpty(list: Nil): list is Nil;
|
||||
declare function isEmpty<T>(list: List<T>): list is Nil;
|
||||
declare let listA: {
|
||||
value: number;
|
||||
next: Cons<number> | Nil;
|
||||
};
|
||||
declare let listB: Nil;
|
||||
declare let listC: List<number>;
|
||||
@@ -0,0 +1,56 @@
|
||||
tests/cases/conformance/functions/overloadsWithTypePredicates03.ts(2,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
|
||||
tests/cases/conformance/functions/overloadsWithTypePredicates03.ts(3,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
|
||||
tests/cases/conformance/functions/overloadsWithTypePredicates03.ts(4,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
|
||||
tests/cases/conformance/functions/overloadsWithTypePredicates03.ts(5,10): error TS2394: Overload signature is not compatible with function implementation.
|
||||
|
||||
|
||||
==== tests/cases/conformance/functions/overloadsWithTypePredicates03.ts (4 errors) ====
|
||||
|
||||
function is(x: any, type: "number"): x is number;
|
||||
~~
|
||||
!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
|
||||
function is(x: any, type: "string"): x is string;
|
||||
~~
|
||||
!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
|
||||
function is(x: any, type: "boolean"): x is boolean;
|
||||
~~
|
||||
!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
|
||||
function is(x: any, type: string): x is (number | boolean | string);
|
||||
~~
|
||||
!!! error TS2394: Overload signature is not compatible with function implementation.
|
||||
function is(x: any, type: string): boolean {
|
||||
if (["string", "number", "boolean"].indexOf(type) >= 0) {
|
||||
return typeof x === type;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
declare function myRand(): boolean;
|
||||
|
||||
let strNumOrBool: string | number | boolean;
|
||||
|
||||
if (myRand()) {
|
||||
strNumOrBool = "abc";
|
||||
}
|
||||
else if (myRand()) {
|
||||
strNumOrBool = 100;
|
||||
}
|
||||
else {
|
||||
strNumOrBool = true;
|
||||
}
|
||||
|
||||
if (is(strNumOrBool, "number")) {
|
||||
let num = strNumOrBool;
|
||||
num *= 100;
|
||||
}
|
||||
|
||||
if (is(strNumOrBool, "string")) {
|
||||
let str = strNumOrBool;
|
||||
str = str.slice();
|
||||
}
|
||||
|
||||
if (is(strNumOrBool, "boolean")) {
|
||||
let bool = strNumOrBool;
|
||||
bool = bool || bool && bool;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
//// [overloadsWithTypePredicates03.ts]
|
||||
|
||||
function is(x: any, type: "number"): x is number;
|
||||
function is(x: any, type: "string"): x is string;
|
||||
function is(x: any, type: "boolean"): x is boolean;
|
||||
function is(x: any, type: string): x is (number | boolean | string);
|
||||
function is(x: any, type: string): boolean {
|
||||
if (["string", "number", "boolean"].indexOf(type) >= 0) {
|
||||
return typeof x === type;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
declare function myRand(): boolean;
|
||||
|
||||
let strNumOrBool: string | number | boolean;
|
||||
|
||||
if (myRand()) {
|
||||
strNumOrBool = "abc";
|
||||
}
|
||||
else if (myRand()) {
|
||||
strNumOrBool = 100;
|
||||
}
|
||||
else {
|
||||
strNumOrBool = true;
|
||||
}
|
||||
|
||||
if (is(strNumOrBool, "number")) {
|
||||
let num = strNumOrBool;
|
||||
num *= 100;
|
||||
}
|
||||
|
||||
if (is(strNumOrBool, "string")) {
|
||||
let str = strNumOrBool;
|
||||
str = str.slice();
|
||||
}
|
||||
|
||||
if (is(strNumOrBool, "boolean")) {
|
||||
let bool = strNumOrBool;
|
||||
bool = bool || bool && bool;
|
||||
}
|
||||
|
||||
//// [overloadsWithTypePredicates03.js]
|
||||
function is(x, type) {
|
||||
if (["string", "number", "boolean"].indexOf(type) >= 0) {
|
||||
return typeof x === type;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
var strNumOrBool;
|
||||
if (myRand()) {
|
||||
strNumOrBool = "abc";
|
||||
}
|
||||
else if (myRand()) {
|
||||
strNumOrBool = 100;
|
||||
}
|
||||
else {
|
||||
strNumOrBool = true;
|
||||
}
|
||||
if (is(strNumOrBool, "number")) {
|
||||
var num = strNumOrBool;
|
||||
num *= 100;
|
||||
}
|
||||
if (is(strNumOrBool, "string")) {
|
||||
var str = strNumOrBool;
|
||||
str = str.slice();
|
||||
}
|
||||
if (is(strNumOrBool, "boolean")) {
|
||||
var bool = strNumOrBool;
|
||||
bool = bool || bool && bool;
|
||||
}
|
||||
|
||||
|
||||
//// [overloadsWithTypePredicates03.d.ts]
|
||||
declare function is(x: any, type: "number"): x is number;
|
||||
declare function is(x: any, type: "string"): x is string;
|
||||
declare function is(x: any, type: "boolean"): x is boolean;
|
||||
declare function is(x: any, type: string): x is (number | boolean | string);
|
||||
declare function myRand(): boolean;
|
||||
declare let strNumOrBool: string | number | boolean;
|
||||
Reference in New Issue
Block a user