Merge remote-tracking branch 'origin/master' into moduleAugmentations

This commit is contained in:
Vladimir Matveev
2016-01-14 11:13:48 -08:00
57 changed files with 1177 additions and 184 deletions

View File

@@ -1,6 +1,6 @@
//// [file.tsx]
declare module JSX {
interface Element { }
interface Element { something; }
interface IntrinsicElements { }
}

View File

@@ -2,11 +2,12 @@
declare module JSX {
>JSX : Symbol(JSX, Decl(file.tsx, 0, 0))
interface Element { }
interface Element { something; }
>Element : Symbol(Element, Decl(file.tsx, 0, 20))
>something : Symbol(something, Decl(file.tsx, 1, 20))
interface IntrinsicElements { }
>IntrinsicElements : Symbol(IntrinsicElements, Decl(file.tsx, 1, 22))
>IntrinsicElements : Symbol(IntrinsicElements, Decl(file.tsx, 1, 33))
}
interface Obj1 {

View File

@@ -2,8 +2,9 @@
declare module JSX {
>JSX : any
interface Element { }
interface Element { something; }
>Element : Element
>something : any
interface IntrinsicElements { }
>IntrinsicElements : IntrinsicElements

View File

@@ -0,0 +1,37 @@
//// [file.tsx]
import React = require('react');
const Foo = (props: any) => <div/>;
// Should be OK
const foo = <Foo />;
// Should be OK
var MainMenu: React.StatelessComponent<{}> = (props) => (<div>
<h3>Main Menu</h3>
</div>);
var App: React.StatelessComponent<{ children }> = ({children}) => (
<div >
<MainMenu/>
</div>
);
//// [file.jsx]
define(["require", "exports", 'react'], function (require, exports, React) {
"use strict";
var Foo = function (props) { return <div />; };
// Should be OK
var foo = <Foo />;
// Should be OK
var MainMenu = function (props) { return (<div>
<h3>Main Menu</h3>
</div>); };
var App = function (_a) {
var children = _a.children;
return (<div>
<MainMenu />
</div>);
};
});

View File

@@ -0,0 +1,48 @@
=== tests/cases/conformance/jsx/file.tsx ===
import React = require('react');
>React : Symbol(React, Decl(file.tsx, 0, 0))
const Foo = (props: any) => <div/>;
>Foo : Symbol(Foo, Decl(file.tsx, 3, 5))
>props : Symbol(props, Decl(file.tsx, 3, 13))
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 927, 45))
// Should be OK
const foo = <Foo />;
>foo : Symbol(foo, Decl(file.tsx, 5, 5))
>Foo : Symbol(Foo, Decl(file.tsx, 3, 5))
// Should be OK
var MainMenu: React.StatelessComponent<{}> = (props) => (<div>
>MainMenu : Symbol(MainMenu, Decl(file.tsx, 9, 3))
>React : Symbol(React, Decl(file.tsx, 0, 0))
>StatelessComponent : Symbol(React.StatelessComponent, Decl(react.d.ts, 139, 5))
>props : Symbol(props, Decl(file.tsx, 9, 46))
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 927, 45))
<h3>Main Menu</h3>
>h3 : Symbol(JSX.IntrinsicElements.h3, Decl(react.d.ts, 939, 48))
>h3 : Symbol(JSX.IntrinsicElements.h3, Decl(react.d.ts, 939, 48))
</div>);
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 927, 45))
var App: React.StatelessComponent<{ children }> = ({children}) => (
>App : Symbol(App, Decl(file.tsx, 13, 3))
>React : Symbol(React, Decl(file.tsx, 0, 0))
>StatelessComponent : Symbol(React.StatelessComponent, Decl(react.d.ts, 139, 5))
>children : Symbol(children, Decl(file.tsx, 13, 35))
>children : Symbol(children, Decl(file.tsx, 13, 52))
<div >
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 927, 45))
<MainMenu/>
>MainMenu : Symbol(MainMenu, Decl(file.tsx, 9, 3))
</div>
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 927, 45))
);

View File

@@ -0,0 +1,59 @@
=== tests/cases/conformance/jsx/file.tsx ===
import React = require('react');
>React : typeof React
const Foo = (props: any) => <div/>;
>Foo : (props: any) => JSX.Element
>(props: any) => <div/> : (props: any) => JSX.Element
>props : any
><div/> : JSX.Element
>div : any
// Should be OK
const foo = <Foo />;
>foo : JSX.Element
><Foo /> : JSX.Element
>Foo : (props: any) => JSX.Element
// Should be OK
var MainMenu: React.StatelessComponent<{}> = (props) => (<div>
>MainMenu : React.StatelessComponent<{}>
>React : any
>StatelessComponent : React.StatelessComponent<P>
>(props) => (<div> <h3>Main Menu</h3></div>) : (props: {}) => JSX.Element
>props : {}
>(<div> <h3>Main Menu</h3></div>) : JSX.Element
><div> <h3>Main Menu</h3></div> : JSX.Element
>div : any
<h3>Main Menu</h3>
><h3>Main Menu</h3> : JSX.Element
>h3 : any
>h3 : any
</div>);
>div : any
var App: React.StatelessComponent<{ children }> = ({children}) => (
>App : React.StatelessComponent<{ children: any; }>
>React : any
>StatelessComponent : React.StatelessComponent<P>
>children : any
>({children}) => ( <div > <MainMenu/> </div>) : ({children}: { children: any; }) => JSX.Element
>children : any
>( <div > <MainMenu/> </div>) : JSX.Element
<div >
><div > <MainMenu/> </div> : JSX.Element
>div : any
<MainMenu/>
><MainMenu/> : JSX.Element
>MainMenu : React.StatelessComponent<{}>
</div>
>div : any
);

View File

@@ -7,9 +7,23 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(37,13): err
Property 'q' is missing in type 'SomeDerived'.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(38,13): error TS2352: Neither type 'SomeBase' nor type 'SomeOther' is assignable to the other.
Property 'q' is missing in type 'SomeBase'.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,5): error TS2304: Cannot find name 'numOrStr'.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,14): error TS1005: '>' expected.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,14): error TS2304: Cannot find name 'is'.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,17): error TS1005: ')' expected.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,17): error TS2304: Cannot find name 'string'.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,48): error TS1005: ';' expected.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(45,2): error TS2322: Type 'number | string' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,32): error TS2304: Cannot find name 'numOrStr'.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,41): error TS1005: ')' expected.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,41): error TS2304: Cannot find name 'is'.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,44): error TS1005: ';' expected.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,44): error TS2304: Cannot find name 'string'.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,50): error TS1005: ';' expected.
==== tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts (5 errors) ====
==== tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts (18 errors) ====
// Function call whose argument is a 1 arg generic function call with explicit type arguments
function fn1<T>(t: T) { }
function fn2(t: any) { }
@@ -64,5 +78,41 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(38,13): err
!!! error TS2352: Property 'q' is missing in type 'SomeBase'.
someOther = <SomeOther>someOther;
// Type assertion cannot be a type-predicate type
var numOrStr: number | string;
var str: string;
if(<numOrStr is string>(numOrStr === undefined)) { // Error
~~~~~~~~
!!! error TS2304: Cannot find name 'numOrStr'.
~~
!!! error TS1005: '>' expected.
~~
!!! error TS2304: Cannot find name 'is'.
~~~~~~
!!! error TS1005: ')' expected.
~~~~~~
!!! error TS2304: Cannot find name 'string'.
~
!!! error TS1005: ';' expected.
str = numOrStr; // Error, no narrowing occurred
~~~
!!! error TS2322: Type 'number | string' is not assignable to type 'string'.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
}
if((numOrStr === undefined) as numOrStr is string) { // Error
~~~~~~~~
!!! error TS2304: Cannot find name 'numOrStr'.
~~
!!! error TS1005: ')' expected.
~~
!!! error TS2304: Cannot find name 'is'.
~~~~~~
!!! error TS1005: ';' expected.
~~~~~~
!!! error TS2304: Cannot find name 'string'.
~
!!! error TS1005: ';' expected.
}

View File

@@ -39,6 +39,15 @@ someOther = <SomeOther>someDerived; // Error
someOther = <SomeOther>someBase; // Error
someOther = <SomeOther>someOther;
// Type assertion cannot be a type-predicate type
var numOrStr: number | string;
var str: string;
if(<numOrStr is string>(numOrStr === undefined)) { // Error
str = numOrStr; // Error, no narrowing occurred
}
if((numOrStr === undefined) as numOrStr is string) { // Error
}
@@ -87,3 +96,16 @@ someDerived = someOther; // Error
someOther = someDerived; // Error
someOther = someBase; // Error
someOther = someOther;
// Type assertion cannot be a type-predicate type
var numOrStr;
var str;
if (is)
string > (numOrStr === undefined);
{
str = numOrStr; // Error, no narrowing occurred
}
if ((numOrStr === undefined))
is;
string;
{
}

View File

@@ -1,15 +1,21 @@
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(2,7): error TS2300: Duplicate identifier 'A'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(15,12): error TS2322: Type 'string' is not assignable to type 'x is A'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(18,55): error TS2304: Cannot find name 'x'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(18,57): error TS1144: '{' or ';' expected.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(18,57): error TS2304: Cannot find name 'is'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(18,60): error TS1005: ';' expected.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(18,62): error TS1005: ';' expected.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(22,33): error TS2304: Cannot find name 'x'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(26,33): error TS1225: Cannot find parameter 'x'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(30,10): error TS2391: Function implementation is missing or not immediately following the declaration.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(31,5): error TS1131: Property or signature expected.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(31,5): error TS7027: Unreachable code detected.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(32,1): error TS1128: Declaration or statement expected.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(34,38): error TS1225: Cannot find parameter 'x'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(38,51): error TS2322: Type 'B' is not assignable to type 'A'.
Property 'propA' is missing in type 'B'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(42,56): error TS2322: Type 'number' is not assignable to type 'string'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(46,56): error TS2322: Type 'T[]' is not assignable to type 'string'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(50,1): error TS7027: Unreachable code detected.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(60,7): error TS2339: Property 'propB' does not exist on type 'A'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(65,7): error TS2339: Property 'propB' does not exist on type 'A'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(70,7): error TS2339: Property 'propB' does not exist on type 'A'.
@@ -23,27 +29,40 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(85,1):
Type predicate 'p2 is A' is not assignable to 'p1 is A'.
Parameter 'p2' is not in the same position as parameter 'p1'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(91,1): error TS2322: Type '(p1: any, p2: any, p3: any) => p1 is A' is not assignable to type '(p1: any, p2: any) => p1 is A'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(96,9): error TS1228: A type predicate is only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(97,16): error TS1228: A type predicate is only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(98,20): error TS1228: A type predicate is only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(96,9): error TS2304: Cannot find name 'b'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(96,11): error TS1005: '=' expected.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(96,11): error TS2304: Cannot find name 'is'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(96,14): error TS1005: ',' expected.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(96,14): error TS2300: Duplicate identifier 'A'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(97,16): error TS2304: Cannot find name 'b'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(97,18): error TS1005: '=' expected.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(97,18): error TS2304: Cannot find name 'is'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(97,21): error TS1005: ',' expected.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(98,20): error TS2304: Cannot find name 'b'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(98,22): error TS1144: '{' or ';' expected.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(98,22): error TS2304: Cannot find name 'is'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(98,25): error TS1005: ';' expected.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(98,27): error TS1005: ';' expected.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(105,16): error TS2322: Type 'boolean' is not assignable to type 'D'.
Property 'm1' is missing in type 'Boolean'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(105,16): error TS2409: Return type of constructor signature must be assignable to the instance type of the class
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(107,20): error TS1228: A type predicate is only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(110,20): error TS1228: A type predicate is only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(111,16): error TS2408: Setters cannot return a value.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(116,18): error TS1228: A type predicate is only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(120,22): error TS1225: Cannot find parameter 'p1'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(120,22): error TS1228: A type predicate is only allowed in return type position for functions and methods.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(120,22): error TS2304: Cannot find name 'p1'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(120,25): error TS1005: ';' expected.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(120,25): error TS2304: Cannot find name 'is'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(120,28): error TS1005: ';' expected.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(121,1): error TS1128: Declaration or statement expected.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(124,20): error TS1229: A type predicate cannot reference a rest parameter.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(129,34): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(133,34): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(137,39): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern.
==== tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts (33 errors) ====
==== tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts (50 errors) ====
class A {
~
!!! error TS2300: Duplicate identifier 'A'.
propA: number;
}
@@ -62,6 +81,16 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(137,39
}
function hasTypeGuardTypeInsideTypeGuardType(x): x is x is A {
~
!!! error TS2304: Cannot find name 'x'.
~~
!!! error TS1144: '{' or ';' expected.
~~
!!! error TS2304: Cannot find name 'is'.
~
!!! error TS1005: ';' expected.
~
!!! error TS1005: ';' expected.
return true;
}
@@ -83,6 +112,8 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(137,39
return true;
~~~~~~
!!! error TS1131: Property or signature expected.
~~~~~~
!!! error TS7027: Unreachable code detected.
}
~
!!! error TS1128: Declaration or statement expected.
@@ -113,8 +144,6 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(137,39
}
let a: A;
~~~
!!! error TS7027: Unreachable code detected.
let b: B;
declare function isB(p1): p1 is B;
@@ -181,14 +210,36 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(137,39
// Type predicates in non-return type positions
var b1: b is A;
~~~~~~
!!! error TS1228: A type predicate is only allowed in return type position for functions and methods.
~
!!! error TS2304: Cannot find name 'b'.
~~
!!! error TS1005: '=' expected.
~~
!!! error TS2304: Cannot find name 'is'.
~
!!! error TS1005: ',' expected.
~
!!! error TS2300: Duplicate identifier 'A'.
function b2(a: b is A) {};
~~~~~~
!!! error TS1228: A type predicate is only allowed in return type position for functions and methods.
~
!!! error TS2304: Cannot find name 'b'.
~~
!!! error TS1005: '=' expected.
~~
!!! error TS2304: Cannot find name 'is'.
~
!!! error TS1005: ',' expected.
function b3(): A | b is A {
~~~~~~
!!! error TS1228: A type predicate is only allowed in return type position for functions and methods.
~
!!! error TS2304: Cannot find name 'b'.
~~
!!! error TS1144: '{' or ';' expected.
~~
!!! error TS2304: Cannot find name 'is'.
~
!!! error TS1005: ';' expected.
~
!!! error TS1005: ';' expected.
return true;
};
@@ -203,13 +254,9 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(137,39
!!! error TS2409: Return type of constructor signature must be assignable to the instance type of the class
}
get m1(p1: A): p1 is C {
~~~~~~~
!!! error TS1228: A type predicate is only allowed in return type position for functions and methods.
return true;
}
set m2(p1: A): p1 is C {
~~~~~~~
!!! error TS1228: A type predicate is only allowed in return type position for functions and methods.
return true;
~~~~
!!! error TS2408: Setters cannot return a value.
@@ -218,17 +265,21 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(137,39
interface I1 {
new (p1: A): p1 is C;
~~~~~~~
!!! error TS1228: A type predicate is only allowed in return type position for functions and methods.
}
interface I2 {
[index: number]: p1 is C;
~~
!!! error TS1225: Cannot find parameter 'p1'.
~~~~~~~
!!! error TS1228: A type predicate is only allowed in return type position for functions and methods.
!!! error TS2304: Cannot find name 'p1'.
~~
!!! error TS1005: ';' expected.
~~
!!! error TS2304: Cannot find name 'is'.
~
!!! error TS1005: ';' expected.
}
~
!!! error TS1128: Declaration or statement expected.
// Reference to rest parameter
function b4(...a): a is A {

View File

@@ -171,7 +171,9 @@ var C = (function (_super) {
function hasANonBooleanReturnStatement(x) {
return '';
}
function hasTypeGuardTypeInsideTypeGuardType(x) {
is;
A;
{
return true;
}
function hasMissingIsKeyword() {
@@ -224,10 +226,14 @@ assign3 = function (p1, p2, p3) {
return true;
};
// Type predicates in non-return type positions
var b1;
function b2(a) { }
var b1 = is, A;
function b2(a, A) {
if (a === void 0) { a = is; }
}
;
function b3() {
is;
A;
{
return true;
}
;
@@ -252,6 +258,8 @@ var D = (function () {
});
return D;
}());
is;
C;
// Reference to rest parameter
function b4() {
var a = [];

View File

@@ -1,4 +1,4 @@
lib.d.ts(29,18): error TS2300: Duplicate identifier 'eval'.
lib.d.ts(28,18): error TS2300: Duplicate identifier 'eval'.
tests/cases/compiler/variableDeclarationInStrictMode1.ts(2,5): error TS1100: Invalid use of 'eval' in strict mode.
tests/cases/compiler/variableDeclarationInStrictMode1.ts(2,5): error TS2300: Duplicate identifier 'eval'.

View File

@@ -38,4 +38,13 @@ someOther = <SomeOther>someDerived; // Error
someOther = <SomeOther>someBase; // Error
someOther = <SomeOther>someOther;
// Type assertion cannot be a type-predicate type
var numOrStr: number | string;
var str: string;
if(<numOrStr is string>(numOrStr === undefined)) { // Error
str = numOrStr; // Error, no narrowing occurred
}
if((numOrStr === undefined) as numOrStr is string) { // Error
}

View File

@@ -1,7 +1,7 @@
//@filename: file.tsx
//@jsx: preserve
declare module JSX {
interface Element { }
interface Element { something; }
interface IntrinsicElements { }
}

View File

@@ -0,0 +1,23 @@
// @filename: file.tsx
// @jsx: preserve
// @module: amd
// @noLib: true
// @libFiles: react.d.ts,lib.d.ts
import React = require('react');
const Foo = (props: any) => <div/>;
// Should be OK
const foo = <Foo />;
// Should be OK
var MainMenu: React.StatelessComponent<{}> = (props) => (<div>
<h3>Main Menu</h3>
</div>);
var App: React.StatelessComponent<{ children }> = ({children}) => (
<div >
<MainMenu/>
</div>
);

View File

@@ -0,0 +1,13 @@
/// <reference path='fourslash.ts'/>
// @Filename: file1.ts
//// interface interface1 extends interface1 {
//// /*1*/doStuff(): void;
//// /*2*/propName: string;
//// }
let markers = test.markers()
for (let marker of markers) {
goTo.position(marker.position);
verify.documentHighlightsAtPositionCount(1, ["file1.ts"]);
}

View File

@@ -0,0 +1,13 @@
/// <reference path='fourslash.ts'/>
// @Filename: file1.ts
//// class class1 extends class1 {
//// /*1*/doStuff() { }
//// /*2*/propName: string;
//// }
let markers = test.markers()
for (let marker of markers) {
goTo.position(marker.position);
verify.documentHighlightsAtPositionCount(1, ["file1.ts"]);
}

View File

@@ -0,0 +1,17 @@
/// <reference path='fourslash.ts'/>
// @Filename: file1.ts
//// interface interface1 extends interface1 {
//// /*1*/doStuff(): void;
//// /*2*/propName: string;
//// }
////
//// var v: interface1;
//// v./*3*/propName;
//// v./*4*/doStuff();
let markers = test.markers()
for (let marker of markers) {
goTo.position(marker.position);
verify.documentHighlightsAtPositionCount(2, ["file1.ts"]);
}

View File

@@ -0,0 +1,17 @@
/// <reference path='fourslash.ts'/>
// @Filename: file1.ts
//// class class1 extends class1 {
//// /*1*/doStuff() { }
//// /*2*/propName: string;
//// }
////
//// var c: class1;
//// c./*3*/doStuff();
//// c./*4*/propName;
let markers = test.markers()
for (let marker of markers) {
goTo.position(marker.position);
verify.documentHighlightsAtPositionCount(2, ["file1.ts"]);
}

View File

@@ -0,0 +1,30 @@
/// <reference path='fourslash.ts'/>
// @Filename: file1.ts
//// interface C extends D {
//// /*0*/prop0: string;
//// /*1*/prop1: number;
//// }
////
//// interface D extends C {
//// /*2*/prop0: string;
//// /*3*/prop1: number;
//// }
////
//// var d: D;
//// d./*4*/prop1;
goTo.marker("0");
verify.documentHighlightsAtPositionCount(2, ["file1.ts"]);
goTo.marker("1");
verify.documentHighlightsAtPositionCount(3, ["file1.ts"]);
goTo.marker("2");
verify.documentHighlightsAtPositionCount(2, ["file1.ts"]);
goTo.marker("3");
verify.documentHighlightsAtPositionCount(3, ["file1.ts"]);
goTo.marker("4");
verify.documentHighlightsAtPositionCount(3, ["file1.ts"]);

View File

@@ -0,0 +1,30 @@
/// <reference path='fourslash.ts'/>
// @Filename: file1.ts
//// class C extends D {
//// /*0*/prop0: string;
//// /*1*/prop1: string;
//// }
////
//// class D extends C {
//// /*2*/prop0: string;
//// /*3*/prop1: string;
//// }
////
//// var d: D;
//// d./*4*/prop1;
goTo.marker("0");
verify.documentHighlightsAtPositionCount(1, ["file1.ts"]);
goTo.marker("1");
verify.documentHighlightsAtPositionCount(1, ["file1.ts"]);
goTo.marker("2");
verify.documentHighlightsAtPositionCount(1, ["file1.ts"]);
goTo.marker("3");
verify.documentHighlightsAtPositionCount(2, ["file1.ts"]);
goTo.marker("4");
verify.documentHighlightsAtPositionCount(2, ["file1.ts"]);

View File

@@ -0,0 +1,25 @@
/// <reference path='fourslash.ts'/>
//// class class1 extends class1 {
//// [|doStuff|]() { }
//// [|propName|]: string;
//// }
////
//// var v: class1;
//// v.[|doStuff|]();
//// v.[|propName|];
function verifyReferences(query: FourSlashInterface.Range, references: FourSlashInterface.Range[]) {
goTo.position(query.start);
for (const ref of references) {
verify.referencesAtPositionContains(ref);
}
}
const ranges = test.ranges();
verify.assertHasRanges(ranges);
const [r0, r1, r2, r3] = ranges;
verifyReferences(r0, [r0, r2]);
verifyReferences(r1, [r1, r3]);
verifyReferences(r2, [r0, r2]);
verifyReferences(r3, [r1, r3]);

View File

@@ -0,0 +1,25 @@
/// <reference path='fourslash.ts'/>
//// interface interface1 extends interface1 {
//// [|doStuff|](): void; // r0
//// [|propName|]: string; // r1
//// }
////
//// var v: interface1;
//// v.[|doStuff|](); // r2
//// v.[|propName|]; // r3
function verifyReferences(query: FourSlashInterface.Range, references: FourSlashInterface.Range[]) {
goTo.position(query.start);
for (const ref of references) {
verify.referencesAtPositionContains(ref);
}
}
const ranges = test.ranges();
verify.assertHasRanges(ranges);
const [r0, r1, r2, r3] = ranges;
verifyReferences(r0, [r0, r2]);
verifyReferences(r1, [r1, r3]);
verifyReferences(r2, [r0, r2]);
verifyReferences(r3, [r1, r3]);

View File

@@ -0,0 +1,37 @@
/// <reference path='fourslash.ts'/>
//// class class1 extends class1 {
//// [|doStuff|]() { } // r0
//// [|propName|]: string; // r1
//// }
//// interface interface1 extends interface1 {
//// [|doStuff|](): void; // r2
//// [|propName|]: string; // r3
//// }
//// class class2 extends class1 implements interface1 {
//// [|doStuff|]() { } // r4
//// [|propName|]: string; // r5
//// }
////
//// var v: class2;
//// v.[|propName|]; // r6
//// v.[|doStuff|](); // r7
function verifyReferences(query: FourSlashInterface.Range, references: FourSlashInterface.Range[]) {
goTo.position(query.start);
for (const ref of references) {
verify.referencesAtPositionContains(ref);
}
}
const ranges = test.ranges();
verify.assertHasRanges(ranges);
const [r0, r1, r2, r3, r4, r5, r6, r7] = ranges;
verifyReferences(r0, [r0]);
verifyReferences(r1, [r1, r5, r6]);
verifyReferences(r2, [r2, r4, r7]);
verifyReferences(r3, [r3, r5, r6]);
verifyReferences(r4, [r2, r4, r7]);
verifyReferences(r5, [r1, r3, r5, r6]);
verifyReferences(r6, [r1, r3, r5, r6]);
verifyReferences(r7, [r2, r4, r7]);

View File

@@ -0,0 +1,30 @@
/// <reference path='fourslash.ts'/>
//// interface C extends D {
//// [|prop0|]: string; // r0
//// [|prop1|]: number; // r1
//// }
////
//// interface D extends C {
//// [|prop0|]: string; // r2
//// }
////
//// var d: D;
//// d.[|prop0|]; // r3
//// d.[|prop1|]; // r4
function verifyReferences(query: FourSlashInterface.Range, references: FourSlashInterface.Range[]) {
goTo.position(query.start);
for (const ref of references) {
verify.referencesAtPositionContains(ref);
}
}
const ranges = test.ranges();
verify.assertHasRanges(ranges);
const [r0, r1, r2, r3, r4] = ranges;
verifyReferences(r0, [r0, r2, r3]);
verifyReferences(r1, [r1]);
verifyReferences(r2, [r0, r2, r3]);
verifyReferences(r3, [r0, r2, r3]);
verifyReferences(r4, []);

View File

@@ -0,0 +1,30 @@
/// <reference path='fourslash.ts'/>
//// class C extends D {
//// [|prop0|]: string; // r0
//// [|prop1|]: number; // r1
//// }
////
//// class D extends C {
//// [|prop0|]: string; // r2
//// }
////
//// var d: D;
//// d.[|prop0|]; // r3
//// d.[|prop1|]; // r4
function verifyReferences(query: FourSlashInterface.Range, references: FourSlashInterface.Range[]) {
goTo.position(query.start);
for (const ref of references) {
verify.referencesAtPositionContains(ref);
}
}
const ranges = test.ranges();
verify.assertHasRanges(ranges);
const [r0, r1, r2, r3, r4] = ranges;
verifyReferences(r0, [r0]);
verifyReferences(r1, [r1]);
verifyReferences(r2, [r2, r3]);
verifyReferences(r3, [r2, r3]);
verifyReferences(r4, []);

View File

@@ -0,0 +1,15 @@
/// <reference path='fourslash.ts'/>
//// interface interface1 extends interface1 {
//// /*1*/doStuff(): void;
//// /*2*/propName: string;
//// }
////
//// var v: interface1;
//// v./*3*/propName;
//// v./*4*/doStuff();
test.markers().forEach(m => {
goTo.position(m.position, m.fileName);
verify.referencesCountIs(2);
});

View File

@@ -0,0 +1,15 @@
/// <reference path='fourslash.ts'/>
//// class class1 extends class1 {
//// /*1*/doStuff() { }
//// /*2*/propName: string;
//// }
////
//// var c: class1;
//// c./*3*/doStuff();
//// c./*4*/propName;
test.markers().forEach(m => {
goTo.position(m.position, m.fileName);
verify.referencesCountIs(2);
});

View File

@@ -0,0 +1,19 @@
/// <reference path='fourslash.ts'/>
//// interface interface1 extends interface1 {
//// /*1*/doStuff(): void;
//// /*2*/propName: string;
//// }
//// interface interface2 extends interface1 {
//// /*3*/doStuff(): void;
//// /*4*/propName: string;
//// }
////
//// var v: interface1;
//// v./*5*/propName;
//// v./*6*/doStuff();
test.markers().forEach(m => {
goTo.position(m.position, m.fileName);
verify.referencesCountIs(3);
});

View File

@@ -0,0 +1,32 @@
/// <reference path='fourslash.ts'/>
//// class class1 extends class1 {
//// /*1*/doStuff() { }
//// /*2*/propName: string;
//// }
//// class class2 extends class1 {
//// /*3*/doStuff() { }
//// /*4*/propName: string;
//// }
////
//// var v: class2;
//// v./*5*/propName;
//// v./*6*/doStuff();
goTo.marker("1");
verify.referencesCountIs(1);
goTo.marker("2");
verify.referencesCountIs(3);
goTo.marker("3");
verify.referencesCountIs(2);
goTo.marker("4");
verify.referencesCountIs(3);
goTo.marker("5");
verify.referencesCountIs(3);
goTo.marker("6");
verify.referencesCountIs(2);

View File

@@ -0,0 +1,42 @@
/// <reference path='fourslash.ts'/>
//// class class1 extends class1 {
//// /*1*/doStuff() { }
//// /*2*/propName: string;
//// }
//// interface interface1 extends interface1 {
//// /*3*/doStuff(): void;
//// /*4*/propName: string;
//// }
//// class class2 extends class1 implements interface1 {
//// /*5*/doStuff() { }
//// /*6*/propName: string;
//// }
////
//// var v: class2;
//// v./*7*/propName;
//// v./*8*/doStuff();
goTo.marker("1");
verify.referencesCountIs(1);
goTo.marker("2");
verify.referencesCountIs(3);
goTo.marker("3");
verify.referencesCountIs(3);
goTo.marker("4");
verify.referencesCountIs(3);
goTo.marker("5");
verify.referencesCountIs(3);
goTo.marker("6");
verify.referencesCountIs(4);
goTo.marker("7");
verify.referencesCountIs(4);
goTo.marker("8");
verify.referencesCountIs(3);

View File

@@ -0,0 +1,27 @@
/// <reference path='fourslash.ts'/>
//// interface C extends D {
//// /*0*/propD: number;
//// }
//// interface D extends C {
//// /*1*/propD: string;
//// /*3*/propC: number;
//// }
//// var d: D;
//// d./*2*/propD;
//// d./*4*/propC;
goTo.marker("0");
verify.referencesCountIs(3);
goTo.marker("1");
verify.referencesCountIs(3);
goTo.marker("2");
verify.referencesCountIs(3);
goTo.marker("3");
verify.referencesCountIs(2);
goTo.marker("4");
verify.referencesCountIs(2);

View File

@@ -0,0 +1,21 @@
/// <reference path='fourslash.ts'/>
//// class D extends C {
//// /*0*/prop1: string;
//// }
////
//// class C extends D {
//// /*1*/prop1: string;
//// }
////
//// var c: C;
//// c./*2*/prop1;
goTo.marker("0");
verify.referencesCountIs(1);
goTo.marker("1");
verify.referencesCountIs(2)
goTo.marker("2");
verify.referencesCountIs(2)

View File

@@ -0,0 +1,10 @@
/// <reference path='fourslash.ts' />
////import [|a|] from "module";
////export { [|a|] };
let ranges = test.ranges()
for (let range of ranges) {
goTo.position(range.start);
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
}

View File

@@ -0,0 +1,10 @@
/// <reference path='fourslash.ts' />
////import [|foo|] from 'bar';
////const bar = { [|foo|] };
let ranges = test.ranges()
for (let range of ranges) {
goTo.position(range.start);
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
}

View File

@@ -0,0 +1,10 @@
/// <reference path='fourslash.ts' />
////import * as [|foo|] from 'bar';
////const bar = { [|foo|] };
let ranges = test.ranges()
for (let range of ranges) {
goTo.position(range.start);
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
}

View File

@@ -0,0 +1,18 @@
/// <reference path='fourslash.ts' />
////declare namespace N {
//// export var x: number;
////}
////declare module "mod" {
//// export = N;
////}
////declare module "test" {
//// import * as [|N|] from "mod";
//// export { [|N|] }; // Renaming N here would rename
////}
let ranges = test.ranges()
for (let range of ranges) {
goTo.position(range.start);
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
}

View File

@@ -0,0 +1,12 @@
/// <reference path='fourslash.ts' />
////import [|e|] = require("mod4");
////[|e|];
////a = { [|e|] };
////export { [|e|] };
let ranges = test.ranges()
for (let range of ranges) {
goTo.position(range.start);
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
}

View File

@@ -0,0 +1,15 @@
/// <reference path='fourslash.ts'/>
//// class class1 extends class1 {
//// [|propName|]: string;
//// }
////
//// var v: class1;
//// v.[|propName|];
const ranges = test.ranges();
verify.assertHasRanges(ranges);
for (const range of ranges) {
goTo.position(range.start);
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
}

View File

@@ -0,0 +1,15 @@
/// <reference path='fourslash.ts'/>
//// class class1 extends class1 {
//// [|doStuff|]() { }
//// }
////
//// var v: class1;
//// v.[|doStuff|]();
let ranges = test.ranges();
verify.assertHasRanges(ranges);
for (let range of ranges) {
goTo.position(range.start);
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
}

View File

@@ -0,0 +1,15 @@
/// <reference path='fourslash.ts'/>
//// interface interface1 extends interface1 {
//// [|propName|]: string;
//// }
////
//// var v: interface1;
//// v.[|propName|];
let ranges = test.ranges();
verify.assertHasRanges(ranges);
for (let range of ranges) {
goTo.position(range.start);
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
}

View File

@@ -0,0 +1,15 @@
/// <reference path='fourslash.ts'/>
//// interface interface1 extends interface1 {
//// [|doStuff|](): string;
//// }
////
//// var v: interface1;
//// v.[|doStuff|]();
let ranges = test.ranges();
verify.assertHasRanges(ranges);
for (let range of ranges) {
goTo.position(range.start);
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
}

View File

@@ -0,0 +1,17 @@
/// <reference path='fourslash.ts'/>
//// interface C extends D {
//// propC: number;
//// }
//// interface D extends C {
//// [|propD|]: string;
//// }
//// var d: D;
//// d.[|propD|];
const ranges = test.ranges();
verify.assertHasRanges(ranges);
for (const range of ranges) {
goTo.position(range.start);
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
}

View File

@@ -0,0 +1,17 @@
/// <reference path='fourslash.ts'/>
//// interface C extends D {
//// propD: number;
//// }
//// interface D extends C {
//// [|propC|]: number;
//// }
//// var d: D;
//// d.[|propC|];
const ranges = test.ranges();
verify.assertHasRanges(ranges);
for (const range of ranges) {
goTo.position(range.start);
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
}

View File

@@ -0,0 +1,19 @@
/// <reference path='fourslash.ts'/>
//// class C extends D {
//// [|prop1|]: string;
//// }
////
//// class D extends C {
//// prop1: string;
//// }
////
//// var c: C;
//// c.[|prop1|];
const ranges = test.ranges();
verify.assertHasRanges(ranges);
for (const range of ranges) {
goTo.position(range.start);
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
}

View File

@@ -0,0 +1,19 @@
/// <reference path='fourslash.ts'/>
//// class C implements D {
//// [|prop1|]: string;
//// }
////
//// interface D extends C {
//// [|prop1|]: string;
//// }
////
//// var c: C;
//// c.[|prop1|];
const ranges = test.ranges();
verify.assertHasRanges(ranges);
for (const range of ranges) {
goTo.position(range.start);
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
}