Skip to content

nominal typing in class #28956

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

Closed
xiaoxiangmoe opened this issue Dec 11, 2018 · 2 comments
Closed

nominal typing in class #28956

xiaoxiangmoe opened this issue Dec 11, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@xiaoxiangmoe
Copy link
Contributor

TypeScript Version: 3.3.0-dev.201xxxxx

Search Terms:

class, nominal typing, structural typing
Code

interface A {
  color:string
}

interface B {
  color:string
}

const b:B = {
  color:'red'
}



function foo(a:A){
  return String(a)
}

foo(b)


class AA{
  constructor(color:string){
    this.color=color
  }
  color:string
}
class BB{
  constructor(color:string){
    this.color=color
  }
  color:string
}

const bb = new BB('red')


function bar(a:AA){
  return String(a)
}

bar(bb)

Expected behavior:

class should be nominal typing,
show error in bar(bb)

Actual behavior:

class be structural typing,
no error

Playground Link:

structural typing & nominal typing

@j-oliveras
Copy link
Contributor

Duplicate/related to #202, #12936 and PR #28749.

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Dec 11, 2018
@DanielRosenwasser
Copy link
Member

P.S. @j-oliveras I really appreciate you helping out with these issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants