-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Allow calls on unions of dissimilar signatures #29011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
weswigham
merged 13 commits into
microsoft:master
from
weswigham:dissimilar-union-signatures
Dec 20, 2018
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8184037
Add core of new union signature logic and test - needs intersection s…
weswigham 6c2e1e1
Add inversion of variance for class props lookup from union sig returns
weswigham 8ea94cd
Fix lints
weswigham 407054a
Combine parameter names for nicer quick info
weswigham d7c668a
PR feedback 1
weswigham 5df3c69
Merge branch 'master' into dissimilar-union-signatures
weswigham f24c7f5
Fix miscopy
weswigham d28d87f
PR feedback round 2
weswigham f1d78e9
Remove argument name combining because loc :(
weswigham 9c7abc4
Nit cleanup round 3
weswigham 2ef6733
Reinline getTupleTypeForArgumentAtPos
weswigham 875bb0e
Remove a tad more
weswigham 7b2ad7f
No step on sneky off-by-one error
weswigham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
110 changes: 110 additions & 0 deletions
110
tests/baselines/reference/callsOnComplexSignatures.errors.txt
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
tests/cases/compiler/callsOnComplexSignatures.tsx(38,19): error TS7006: Parameter 'item' implicitly has an 'any' type. | ||
|
||
|
||
==== tests/cases/compiler/callsOnComplexSignatures.tsx (1 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
import React from "react"; | ||
|
||
// Simple calls from real usecases | ||
function test1() { | ||
type stringType1 = "foo" | "bar"; | ||
type stringType2 = "baz" | "bar"; | ||
|
||
interface Temp1 { | ||
getValue(name: stringType1): number; | ||
} | ||
|
||
interface Temp2 { | ||
getValue(name: stringType2): string; | ||
} | ||
|
||
function test(t: Temp1 | Temp2) { | ||
const z = t.getValue("bar"); // Should be fine | ||
} | ||
} | ||
|
||
function test2() { | ||
interface Messages { | ||
readonly foo: (options: { [key: string]: any, b: number }) => string; | ||
readonly bar: (options: { [key: string]: any, a: string }) => string; | ||
} | ||
|
||
const messages: Messages = { | ||
foo: (options) => "Foo", | ||
bar: (options) => "Bar", | ||
}; | ||
|
||
const test1 = (type: "foo" | "bar") => | ||
messages[type]({ a: "A", b: 0 }); | ||
} | ||
|
||
function test3(items: string[] | number[]) { | ||
items.forEach(item => console.log(item)); | ||
~~~~ | ||
!!! error TS7006: Parameter 'item' implicitly has an 'any' type. | ||
} | ||
|
||
function test4( | ||
arg1: ((...objs: {x: number}[]) => number) | ((...objs: {y: number}[]) => number), | ||
arg2: ((a: {x: number}, b: object) => number) | ((a: object, b: {x: number}) => number), | ||
arg3: ((a: {x: number}, ...objs: {y: number}[]) => number) | ((...objs: {x: number}[]) => number), | ||
arg4: ((a?: {x: number}, b?: {x: number}) => number) | ((a?: {y: number}) => number), | ||
arg5: ((a?: {x: number}, ...b: {x: number}[]) => number) | ((a?: {y: number}) => number), | ||
arg6: ((a?: {x: number}, b?: {x: number}) => number) | ((...a: {y: number}[]) => number), | ||
) { | ||
arg1(); | ||
arg1({x: 0, y: 0}); | ||
arg1({x: 0, y: 0}, {x: 1, y: 1}); | ||
|
||
arg2({x: 0}, {x: 0}); | ||
|
||
arg3({x: 0}); | ||
arg3({x: 0}, {x: 0, y: 0}); | ||
arg3({x: 0}, {x: 0, y: 0}, {x: 0, y: 0}); | ||
|
||
arg4(); | ||
arg4({x: 0, y: 0}); | ||
arg4({x: 0, y: 0}, {x: 0}); | ||
|
||
arg5(); | ||
arg5({x: 0, y: 0}); | ||
arg5({x: 0, y: 0}, {x: 0}); | ||
|
||
arg6(); | ||
arg6({x: 0, y: 0}); | ||
arg6({x: 0, y: 0}, {x: 0, y: 0}); | ||
arg6({x: 0, y: 0}, {x: 0, y: 0}, {y: 0}); | ||
} | ||
|
||
// JSX Tag names | ||
function test5() { | ||
// Pair of non-like intrinsics | ||
function render(url?: string): React.ReactNode { | ||
const Tag = url ? 'a' : 'button'; | ||
return <Tag>test</Tag>; | ||
} | ||
|
||
// Union of all intrinsics and components of `any` | ||
function App(props: { component:React.ReactType }) { | ||
const Comp: React.ReactType = props.component; | ||
return (<Comp />); | ||
} | ||
|
||
// custom components with non-subset props | ||
function render2() { | ||
interface P1 { | ||
p?: boolean; | ||
c?: string; | ||
} | ||
interface P2 { | ||
p?: boolean; | ||
c?: any; | ||
d?: any; | ||
} | ||
|
||
var C: React.ComponentType<P1> | React.ComponentType<P2> = null as any; | ||
|
||
const a = <C p={true} />; | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.