forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplest type inference works: id for tuples
```ts tupleId: <...T>(x:...T) => ...T; let t = tupleId(["foo", 1]); let u: [number, string] = t; ``` Some small cleanups scattered around too.
- Loading branch information
Showing
4 changed files
with
133 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,32 @@ | ||
tests/cases/compiler/tupleKinds.ts(7,5): error TS2322: Type '{}' is not assignable to type '[number, string, boolean, C]'. | ||
tests/cases/compiler/tupleKinds.ts(15,5): error TS2322: Type '{}' is not assignable to type '[number, string, boolean, C]'. | ||
Property '0' is missing in type '{}'. | ||
|
||
|
||
==== tests/cases/compiler/tupleKinds.ts (1 errors) ==== | ||
function tupleId<...V>(y:...V): ...V { | ||
return y; | ||
} | ||
function tuple<...T>(...args:...T): ...T { | ||
return args; | ||
} | ||
|
||
let inferredTupleId: [number, string, boolean] = tupleId([1, "foo", false]); | ||
|
||
class C { } | ||
let inferred = tuple(1, "foo", false, new C()); | ||
let match: [number, string, boolean, C] = tuple(1, "foo", false, new C()); | ||
~~~~~ | ||
let acceptType = tuple(4, "qux", false, new C()); | ||
// TODO: Negative cases don't fail yet when you supply complete type arguments | ||
// TODO: Other negative cases | ||
let typeArguments: [number, string, boolean, C] = tuple<[number, string, boolean, C]>(5, "quack", false, new C()); | ||
let inferred: [number, string, boolean, C] = tuple(6, "sequim", false, new C()); | ||
~~~~~~~~ | ||
!!! error TS2322: Type '{}' is not assignable to type '[number, string, boolean, C]'. | ||
!!! error TS2322: Property '0' is missing in type '{}'. | ||
function notSupportedYet<...T>(tuple: number | ...T): number { | ||
if(typeof tuple === 'number') { | ||
return tuple; | ||
} | ||
else { | ||
return -1; | ||
} | ||
|
||
function spreadIntoUnionNotSupportedYet<...T>(tuple: number | ...T): number { | ||
if(typeof tuple === 'number') { | ||
return tuple; | ||
} | ||
else { | ||
return -1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters