Skip to content

Instantly share code, notes, and snippets.

@chrisnicola
Created October 27, 2016 21:56
Show Gist options
  • Save chrisnicola/918f1f0cf3ddf35df2a354514edbf15a to your computer and use it in GitHub Desktop.
Save chrisnicola/918f1f0cf3ddf35df2a354514edbf15a to your computer and use it in GitHub Desktop.
Type inference limitations for Typescript
class TypeOne {
public one
private two
private three
}
class TypeTwo {
public one
}
// Calling a function that requests TypeTwo with a value of TypeOne works
function thisWorks(value: TypeTwo) { return "Worked!" }
thisWorks(new TypeOne())
// Calling a function that requests TypeOne with a value of TypeTwo results in a compile error
function thisFails(value: TypeOne) { return "Failed!" }
thisFails(new TypeTwo())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment