Skip to content
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

infer of selective types #39737

Closed
5 tasks done
Akimotorakiyu opened this issue Jul 25, 2020 · 5 comments
Closed
5 tasks done

infer of selective types #39737

Akimotorakiyu opened this issue Jul 25, 2020 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@Akimotorakiyu
Copy link

Akimotorakiyu commented Jul 25, 2020

Search Terms

infer of selective types

Suggestion

infer of selective types

Use Cases

interface FunInterface {
  < R,P>(params: P): R;
}

let fun: FunInterface ;

let p ="123";
fun<number>("123");
// should be equivalent with `fun<number, typeof p>(p)`
// should be equivalent with `fun<number, string>(p)`

one more thing, Generics by default

function name(p){
  return p
}
// should be  equivalent with
// function name<P>(p:P){
//  return p
// }

const aName = name("someName")
// type of aName is string
const aNumber = name(123)
// type of aNumber is number

Examples

function deal<A extends unknown[], E>(event: E){
  return {
    event,
    fun:(fn:(...args:A))=>{
      eventBus.on(event,fn);
    }
  }
}

const eventName = "notify" as SomeEventType;

deal<[number]>(eventName );
// should be equivalent with `fun<[number], typeof eventName>(eventName );`
// should be equivalent with `fun<[number], SomeEventType>(eventName );`

one more thing, Generics by default

function name<A extends unknown[], B extends SomeType>(p1, a:A, p2:AKindType,  b: B){
  return {p1,a,p2,b}
}
// should be  equivalent with
// function name<A extends unknown[], B extends SomeType,T>(p1:T, a:A, p2:AKindType,  b: B){
//  return {p1,a,p2,b}
// }

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@MartinJohns
Copy link
Contributor

Sounds like a duplicate of #26242.

@Akimotorakiyu
Copy link
Author

@MartinJohns not the same.

@purplesyringa
Copy link

The first example looks like a duplicate, the second one might be new.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jul 29, 2020
@RyanCavanaugh
Copy link
Member

The other part is a duplicate of #17428

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

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

5 participants