Skip to content

Intersect interfaces instead of union #33070

Closed
@Rukomoynikov

Description

@Rukomoynikov

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms: Intersection interfaces, Ternary operator, Intersect interfaces instead of union

Code

const someCondition = true

interface Func1Options { name: string }
interface Func2Options { age: number }

function Func1 (options: Func1Options) { console.log(options) }
function Func2 (options: Func2Options) { console.log(options) }

const selectedFunc = someCondition 
 ? Func1
 : Func2

selectedFunc({
    age: 20,
    name: 'Alastar'
})

Expected behavior:
selectedFunc accepts Func1Options

Actual behavior:
selectedFunc accepts Func1Options & Func2Options

Playground Link: Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions