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

Add NoInfer intrinsic type #52968

Closed
wants to merge 7 commits into from
Closed

Add NoInfer intrinsic type #52968

wants to merge 7 commits into from

Conversation

Andarist
Copy link
Contributor

closes #14829

There is still some work to be done here (type displays on hover, assignability bug, and maybe more) - but I'm pushing this out to receive an early feedback

cc @RyanCavanaugh

@typescript-bot
Copy link
Collaborator

The TypeScript team hasn't accepted the linked issue #14829. If you can get it accepted, this PR will have a better chance of being reviewed.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Feb 25, 2023
@sandersn
Copy link
Member

sandersn commented Mar 7, 2023

@Andarist did you learn anything interesting from the implementation? If so, can you add a report to the end of #14829? Unless @DanielRosenwasser @RyanCavanaugh or @ahejlsberg are interested in taking up this feature in a design meeting, it's likely that this PR will sit until it gets stale.

@sandersn sandersn self-assigned this Mar 7, 2023
@Andarist
Copy link
Contributor Author

@jakebailey would you mind creating a playground for this? :)

@jakebailey
Copy link
Member

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 13, 2023

Heya @jakebailey, I've started to run the tarball bundle task on this PR at 86448ff. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 13, 2023

Hey @jakebailey, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/149238/artifacts?artifactName=tgz&fileId=E040D91AAAB70FE622A8C39FD6DF27B76C392A7C8C3B48C212D760AAF66AFD4702&fileName=/typescript-5.1.0-insiders.20230313.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@5.1.0-pr-52968-5".;

@unional
Copy link
Contributor

unional commented May 1, 2023

Hi, I am reading #14829 and trying to add NoInfer<T> to fix the stub() function in type-plus.

An I notice the type type NoInfer<T> = T & { [K in keyof T]: T[K] } there works with the Animal|Dog example but does not work with:

type NoInfer<T> = T & { [K in keyof T]: T[K] }

type RecursivePartial<T> = {
	[P in keyof T]?: T[P] extends (infer U)[]
		? RecursivePartial<U>[]
		: T[P] extends Record<any, any>
		? RecursivePartial<T[P]>
		: T[P]
}

function foo(v: { a: number, b: string }) {}
function stub<T>(v: RecursivePartial<NoInfer<T>>): T { return v as T }

foo(stub({ a: 1 }) // error

// Argument of type '{ a: number; }' is not assignable to parameter of type '{ a: number; b: string; }'.
// Property 'b' is missing in type '{ a: number; }' but required in type '{ a: number; b: string; }'.

It works with the following type: type NoInfer<T> = Or<IsNull<T>, IsUndefined<T>, T, T & {}>
(where Or<A,B,Then,Else>, IsNull<T>, IsUndefined<T> does what their name suggest).

Just want to bring it up so that this test case is covered in your implementation.
🌷

@Andarist
Copy link
Contributor Author

Andarist commented Jun 5, 2023

@RyanCavanaugh Since 5.2 development has started recently - perhaps we could get some current thoughts from the team about this feature? 😉

@andrewbranch
Copy link
Member

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page.

Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 7, 2023

Heya @andrewbranch, I've started to run the tarball bundle task on this PR at 989fa50. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 7, 2023

Hey @andrewbranch, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/158991/artifacts?artifactName=tgz&fileId=95BBFD2778E2B6F0853A6F2EF1EAB1A4AF470C0AB105BAD2C44C6707C2F2A1D302&fileName=/typescript-5.4.0-insiders.20231207.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@5.4.0-pr-52968-11".;

@Andarist
Copy link
Contributor Author

superseded by #56794

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Suggestion: Noninferential type parameter usage
6 participants